Skip to content
View in the app

A better way to browse. Learn more.

FMForums.com

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

remove leading zeros, not that simple

Featured Replies

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 by Guest

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 )

)

How about:

Let ( [

start = Position ( Input ; Left ( GetAsNumber ( Input ) ; 1 ) ; 1 ; 1 )

] ;

Right ( Input ; Length ( Input ) - start + 1 )

)

But LaRetta, that would get rid of all the zeros, not just the leading ones.

Edited by Guest
fixed LaRetta's name

I realized that although it isn't in the sample text provided. And that's why I deleted my post before you even responded. :wink2:

La[color:green]Retta

My suggestion would be this:

Substitute ( Trim(Substitute ( aNumberWithLeading ; "0" ; " " )) ; " " ; "0" )

--sd

Sweet. :waytogo:

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

Told you there'd be an easier way :)

My suggestion would be this:

Substitute ( Trim(Substitute ( aNumberWithLeading ; "0" ; " " )) ; " " ; "0" )

... Doesn't that remove trailing zero's?

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 by Guest
Added a link to a similar thread.

  • 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

... 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...

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.

  • 10 months later...

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, B) I need to write a code that will remove all the occurrences of "/" from a string

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

Substitute( string ; "/" ; "" )

What's wrong with Get(SystemDrive) ?

Create an account or sign in to comment

Important Information

By using this site, you agree to our Terms of Use.

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.