Jump to content
Claris Engage 2025 - March 25-26 Austin Texas ×
The Claris Museum: The Vault of FileMaker Antiquities at Claris Engage 2025! ×

This topic is 6258 days old. Please don't post here. Open a new topic instead.

Recommended Posts

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

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 )

)

Posted (edited)

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

Edited by Guest
fixed LaRetta's name
Posted

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

Posted

My suggestion would be this:

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

--sd

Posted

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

Posted

My suggestion would be this:

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

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

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

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

Posted

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

Posted

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

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

Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

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