January 20, 200719 yr 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, 200719 yr by Guest
January 20, 200719 yr 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 ) )
January 20, 200719 yr How about: Let ( [ start = Position ( Input ; Left ( GetAsNumber ( Input ) ; 1 ) ; 1 ; 1 ) ] ; Right ( Input ; Length ( Input ) - start + 1 ) )
January 20, 200719 yr But LaRetta, that would get rid of all the zeros, not just the leading ones. Edited January 20, 200719 yr by Guest fixed LaRetta's name
January 20, 200719 yr 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
January 20, 200719 yr My suggestion would be this: Substitute ( Trim(Substitute ( aNumberWithLeading ; "0" ; " " )) ; " " ; "0" ) --sd
January 20, 200719 yr 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
January 20, 200719 yr My suggestion would be this: Substitute ( Trim(Substitute ( aNumberWithLeading ; "0" ; " " )) ; " " ; "0" ) ... Doesn't that remove trailing zero's?
January 20, 200719 yr 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, 200719 yr by Guest Added a link to a similar thread.
January 21, 200719 yr Author 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
January 21, 200719 yr ... 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...
January 21, 200719 yr 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.
December 5, 200718 yr 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
December 5, 200718 yr 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
Create an account or sign in to comment