chapeau_melon Posted January 20, 2007 Posted January 20, 2007 (edited) Hello, This the data 0001234567 0012345678 0123456789 00123-4567 As you can see, I can't work with numeric fields cause of the '-' witch I have to keep absolutly. The question is : Is only want to keep the 12345678 and 123-4567. How can I get rid of these leading zero's ? Kind Regards Edited January 20, 2007 by Guest
Genx Posted January 20, 2007 Posted January 20, 2007 Well, this works, but theres probably an easier way of doing it... Let( [x = "0000012-332310" ; firstNum = Min( If( Position( x ; "1" ; 1 ; 1 ) ; Position( x ; "1" ; 1 ; 1 ) ) ; If( Position( x ; "2" ; 1 ; 1 ) ; Position( x ; "2" ; 1 ; 1 ) ) ; If( Position( x ; "3" ; 1 ; 1 ) ; Position( x ; "3" ; 1 ; 1 ) ) ; If( Position( x ; "4" ; 1 ; 1 ) ; Position( x ; "4" ; 1 ; 1 ) ) ; If( Position( x ; "5" ; 1 ; 1 ) ; Position( x ; "5" ; 1 ; 1 ) ) ; If( Position( x ; "6" ; 1 ; 1 ) ; Position( x ; "6" ; 1 ; 1 ) ) ; If( Position( x ; "7" ; 1 ; 1 ) ; Position( x ; "7" ; 1 ; 1 ) ) ; If( Position( x ; "8" ; 1 ; 1 ) ; Position( x ; "8" ; 1 ; 1 ) ) ; If( Position( x ; "9" ; 1 ; 1 ) ; Position( x ; "9" ; 1 ; 1 ) ) )]; Right( x ; Length(x) - firstNum + 1 ) )
comment Posted January 20, 2007 Posted January 20, 2007 How about: Let ( [ start = Position ( Input ; Left ( GetAsNumber ( Input ) ; 1 ) ; 1 ; 1 ) ] ; Right ( Input ; Length ( Input ) - start + 1 ) )
mr_vodka Posted January 20, 2007 Posted January 20, 2007 (edited) But LaRetta, that would get rid of all the zeros, not just the leading ones. Edited January 20, 2007 by Guest fixed LaRetta's name
LaRetta Posted January 20, 2007 Posted January 20, 2007 I realized that although it isn't in the sample text provided. And that's why I deleted my post before you even responded. La[color:green]Retta
Søren Dyhr Posted January 20, 2007 Posted January 20, 2007 My suggestion would be this: Substitute ( Trim(Substitute ( aNumberWithLeading ; "0" ; " " )) ; " " ; "0" ) --sd
Raybaudi Posted January 20, 2007 Posted January 20, 2007 that is near to mine: Substitute (Trim ( Substitute ( code & "XYZ" ; 0 ; " " ) ) ;[ " " ; 0];["XYZ";"" ]) the "XYZ" part is to avoid to lose trailing zeros BTW: both our formulas fail if there is a space into the code; in such case the best is comment's calc
Genx Posted January 20, 2007 Posted January 20, 2007 My suggestion would be this: Substitute ( Trim(Substitute ( aNumberWithLeading ; "0" ; " " )) ; " " ; "0" ) ... Doesn't that remove trailing zero's?
comment Posted January 20, 2007 Posted January 20, 2007 (edited) our formulas fail if there is a space into the code That is easily solved by hiding the spaces first: Substitute ( Trim ( Substitute ( Input & "§" ; [ " " ; "§" ] ; [ "0" ; " " ] ) ) ; [ " " ; "0" ] ; [ "§" ; " " ] ) That would have been my suggestion for removing leading character runs in general*. But since here we have a special case of numbers, we can do with a shorter formula. --- (*) See a "mirror" formula here. Edited January 20, 2007 by Guest Added a link to a similar thread.
chapeau_melon Posted January 21, 2007 Author Posted January 21, 2007 Thanks to you all for brainstorming on this. In a other forum I got a clean and nice solution that works, since I used Advanced. Removezeros (text) = Code: Case (Length(text>0); Case (Left (text;1) =0 ; removezeros (Right(text;Length(text)-1));text ) ) Tx again to you all
Genx Posted January 21, 2007 Posted January 21, 2007 ... don't think it's really worth using a recursive custom function for it ... either of comments suggested methods will be a lot quicker, but okay...
comment Posted January 21, 2007 Posted January 21, 2007 I think a couple of notes may be in order here: First, the condition: Case (Length(text>0); is ALWAYS true: the expression "text>0" returns either 0 or 1. The length of both is 1, therefore true. I suppose the real intention here was to write: Case ( Length ( text ) > 0 ; but such condition is redundant, since if the text is empty, then the next condition, Case (Left (text;1) =0; cannot be true, and the default result of text is returned - in this case the empty input. So this can be written simply as: Case ( Left ( text ; 1 ) = "0" ; removezeros ( Right ( text ; Length ( text ) - 1 ) ) ; text ) The reason no one here suggested a custom function (well, at least me) is that a custom function requires more resources, both from the programmer and from the CPU. Since a simple non-recursive solution exists, there are no advantages gained from these additional efforts.
josh guff Posted December 5, 2007 Posted December 5, 2007 I realized that although it isn't in the sample text provided. And that's why I deleted my post before you even responded. LaRetta I really wish you hadn't, I need to write a code that will remove all the occurrences of "/" from a string
josh guff Posted December 5, 2007 Posted December 5, 2007 actually just figured it out, funny how thats always works Substitute ( Left ( Get ( DesktopPath ) ; Position ( Get ( DesktopPath ) ; "/" ; 2 ; 1 ) ) ; "/" ; "" ) returns the name of the main hard drive, used for some apple script that deletes a temporary file from the user's desktop after it is no longer needed
Recommended Posts
This topic is 6258 days old. Please don't post here. Open a new topic instead.
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now