1400 Views    -    15 Replies


Username Post: Remove leading zeros        (Topic#213457)
Your continued generosity and support of FMForums is greatly appreciated.
rheinport 
apprentice
Posts: 168

Loc: USA
Post Rank (AVG):
            


FMP: 11 Advanced
OS: Mac OS X Snow Leopard

Member: TechNet, FBA
Skill: Intermediate

Certified:
     



Tweet This! Tweet This Post!
02-18-10 07:46 AM - Post#350885     - Post Rank:             


I'm stuck in my though process...

What's the easiest way to remove any number of leading "0"s from a string?

005602

or

00067800
http://www.rheinport.com











LaRetta 
Developer
Posts: 7467
LaRetta

Post Rank (AVG):
            


FMP: 11 Advanced
OS: Cross Platform

Member: TechNet, FBA

 FMPug

Tweet This! Tweet This Post!
02-18-10 07:54 AM - Post#350887     - Post Rank:             
    In response to rheinport

GetAsNumber ( field )

UPDATE: It doesn't matter if your field is text or number. You can use Replace Field Contents[], back up first or looping script. If you want, you can also add it as auto-enter (replace). If changing your data, remember to protect from record locking as well.


Edited by LaRetta on 02-18-10 07:56 AM. Reason for edit: Added update










mr_vodka 
Candy is Dandy... But Liquor is Quicker
Posts: 5557
mr_vodka

Loc: Charlotte, NC
Post Rank (AVG):
            


FMP: 11 Advanced
OS: Windows XP

Member: TechNet, FBA

Certified:
     

 FMPug

Tweet This! Tweet This Post!
02-18-10 07:55 AM - Post#350888     - Post Rank:             
    In response to rheinport

Well if its only numbers then you can use GetAsNumber or Evaluate.


*Edit - LaRetta beat me to the punch.
-John
Vodka Productions
FMfunctions.com, Co-founder


Edited by mr_vodka on 02-18-10 07:55 AM. Reason for edit: No reason given.










rheinport 
apprentice
Posts: 168

Loc: USA
Post Rank (AVG):
            


FMP: 11 Advanced
OS: Mac OS X Snow Leopard

Member: TechNet, FBA
Skill: Intermediate

Certified:
     



Tweet This! Tweet This Post!
02-18-10 07:57 AM - Post#350889     - Post Rank:             
    In response to mr_vodka

What if it's not only numbers?

A part number could contain

0056SET-M34

Or what if the field contains "Michael"?

PS: Thank's for competing to help me! :-)
http://www.rheinport.com











rheinport 
apprentice
Posts: 168

Loc: USA
Post Rank (AVG):
            


FMP: 11 Advanced
OS: Mac OS X Snow Leopard

Member: TechNet, FBA
Skill: Intermediate

Certified:
     



Tweet This! Tweet This Post!
02-18-10 08:18 AM - Post#350891     - Post Rank:             
    In response to rheinport

I tried

GetAsNumber and Evaluate

in my "Set Field (Calculation)" script step, but it didn't work.
http://www.rheinport.com











TheTominator 
master
Posts: 316

Post Rank (AVG):
            


FMP: 10 Advanced
OS: Cross Platform

Member: TechNet
Skill: Advance



Tweet This! Tweet This Post!
02-18-10 08:32 AM - Post#350895     - Post Rank:             
    In response to rheinport

This isn't the easiest way, but it is robust against all that you have so far described.

Let(
[
origStringLen = Length(StringWithLeadingZeros);
nonZeroString = Filter(StringWithLeadingZeros; Substitute(StringWithLeadingZeros; "0"; ""));
posFirstNonzero = Position(StringWithLeadingZeros; Left(nonZeroString ;1); 1; 1)
];

Case(
nonZeroString = ""; "";
posFirstNonzero = 0; "";
Middle(StringWithLeadingZeros; posFirstNonZero; origStringLen - posFirstNonZero + 1)
)

)











rheinport 
apprentice
Posts: 168

Loc: USA
Post Rank (AVG):
            


FMP: 11 Advanced
OS: Mac OS X Snow Leopard

Member: TechNet, FBA
Skill: Intermediate

Certified:
     



Tweet This! Tweet This Post!
02-18-10 08:39 AM - Post#350897     - Post Rank:             
    In response to TheTominator

It works!!!

Amazing, I could have never done that...

THANK YOU
http://www.rheinport.com











comment 
consultant
Posts: 15253
comment

Post Rank (AVG):
            


FMP: 7 Advanced
OS: Mac OS X Panther



Tweet This! Tweet This Post!
02-18-10 09:06 AM - Post#350900     - Post Rank:             
    In response to rheinport

I have a small bone to pick here: I am quite sure that GetAsNumber() should work perfectly well here. I didn't think a more complicated formula was necessary. However, you say that it works while GetAsNumber() doesn't - and I'd like to know why.










mr_vodka 
Candy is Dandy... But Liquor is Quicker
Posts: 5557
mr_vodka

Loc: Charlotte, NC
Post Rank (AVG):
            


FMP: 11 Advanced
OS: Windows XP

Member: TechNet, FBA

Certified:
     

 FMPug

Tweet This! Tweet This Post!
02-18-10 09:09 AM - Post#350903     - Post Rank:             
    In response to comment

Hi Michael.

I think you may have missed the one subsequent post where he states that the field has a mixture of numbers, symbols, and text.


  • rheinport Said:
What if it's not only numbers?

A part number could contain

0056SET-M34

Or what if the field contains "Michael"?




-John
Vodka Productions
FMfunctions.com, Co-founder


Edited by mr_vodka on 02-18-10 09:10 AM. Reason for edit: No reason given.










TheTominator 
master
Posts: 316

Post Rank (AVG):
            


FMP: 10 Advanced
OS: Cross Platform

Member: TechNet
Skill: Advance



Tweet This! Tweet This Post!
02-18-10 09:10 AM - Post#350904     - Post Rank:             
    In response to comment

  • comment Said:
I have a small bone to pick here: I am quite sure that GetAsNumber() should work perfectly well here. I didn't think a more complicated formula was necessary. However, you say that it works while and GetAsNumber() doesn't - and I'd like to know why.




The original poster asked about removing leading zeroes from a string. While the original post had pure numeric digits in the string, an additional requirement was added in a later post, i.e. it must work for non-numbers such as 0056SET-M34.

GetAsNumber("0056SET-M34") yields "5634" whereas the desired result is "56SET-M34".

Please let me know if you need further clarification.










comment 
consultant
Posts: 15253
comment

Post Rank (AVG):
            


FMP: 7 Advanced
OS: Mac OS X Panther



Tweet This! Tweet This Post!
02-18-10 09:29 AM - Post#350908     - Post Rank:             
    In response to mr_vodka

Indeed, I have missed that post. But in such case, the formula can be somewhat simpler:

Code:

  Let ( [ clean Substitute text "0" "" ) ; start Position text Left clean ) ; ) ] ; Right text Length text ) - start ) )  














rheinport 
apprentice
Posts: 168

Loc: USA
Post Rank (AVG):
            


FMP: 11 Advanced
OS: Mac OS X Snow Leopard

Member: TechNet, FBA
Skill: Intermediate

Certified:
     



Tweet This! Tweet This Post!
02-18-10 09:42 AM - Post#350915     - Post Rank:             
    In response to comment

Thanks comment!

PS: whenever I get an email notification about a post of yours, it reads "Carpal Tunnel" under your forum name "comment" - though I let you know in case you're not aware of it.
http://www.rheinport.com











TheTominator 
master
Posts: 316

Post Rank (AVG):
            


FMP: 10 Advanced
OS: Cross Platform

Member: TechNet
Skill: Advance



Tweet This! Tweet This Post!
02-18-10 09:49 AM - Post#350916     - Post Rank:             
    In response to comment

  • comment Said:

Code:

  Let ( [ clean Substitute text "0" "" ) ; start Position text Left clean ) ; ) ] ; Right text Length text ) - start ) )  







For an input of "000" this calculation yields "000".

It is my understanding that all zeros at the beginning of the string are to be removed, but there may be some ambiguity in the requirements. It could be that there will never be an input string that consists solely of zeros and thus this situation will never arise, or that the correct answer is "000" when provide with an input of "000".










mr_vodka 
Candy is Dandy... But Liquor is Quicker
Posts: 5557
mr_vodka

Loc: Charlotte, NC
Post Rank (AVG):
            


FMP: 11 Advanced
OS: Windows XP

Member: TechNet, FBA

Certified:
     

 FMPug

Tweet This! Tweet This Post!
02-18-10 09:53 AM - Post#350917     - Post Rank:             
    In response to TheTominator

HEre is one that I posted earlier that I took down after seeing all the action on the thread. I am going to repost.


Code:

  Let ( [ YourField;         c Left Substitute x0"" ); );         p Position xc1)       ]; Case ( Right xLength ) - ) )     )  



-John
Vodka Productions
FMfunctions.com, Co-founder











comment 
consultant
Posts: 15253
comment

Post Rank (AVG):
            


FMP: 7 Advanced
OS: Mac OS X Panther



Tweet This! Tweet This Post!
02-18-10 10:15 AM - Post#350921     - Post Rank:             
    In response to rheinport

  • rheinport Said:
whenever I get an email notification about a post of yours, it reads "Carpal Tunnel" under your forum name "comment" - though I let you know in case you're not aware of it.



Thanks. There's not much I can do about it - but perhaps Stephen will notice this.











Your continued generosity and support of FMForums is greatly appreciated.
_henry_ 
journeyman
Posts: 255
_henry_

Loc: Jakarta, Indonesia
Post Rank (AVG):
            


FMP: 9 Advanced
OS: Windows XP



Tweet This! Tweet This Post!
02-18-10 07:26 PM - Post#350958     - Post Rank:             
    In response to rheinport

Hi,

You can take a look at this CF as your reference from Brian dunning website. I used this CF for removing leading zeroes.

Removing Leading Zeroes

For your convenience, I just grabbed directly from the website:

  • Quote:
Let([
C1 = PatternCount("0"; Left(text; 1));

Ca = C1 ];
If(Ca;
TrimLZ(Middle(text; 1 + C1; Length(text) - Ca));
Text)
)

/*Inspiration & much code from: Ray Cologon, NightWing Enterprises*/

Everything has their own time and place...











Icon Legend Permissions Topic Options
Print Topic

Email Topic

1400 Views
Welcome Guest...
Enter your username and password to login. If you do not have a username you can register one here

Username

Password

Remember me. Help



Forgot Password...


Quick Links
Recent Posts
Active Topics
No Replies
Recent Files
Functions & Scripts
FileMaker Pro Help
FileMaker on Twitter
FileMaker Marketplace

Custom Search

Find FileMaker Developers

Don't have time to wait,
hire a developer now!

Recent Members
Welcome them to our community!
Find FileMaker Jobs

Want a new career?
Find your new job now!

Joy of Tech
Latest Joy of Tech!

Recent Topics
Recent Hot Topics
Contribute
With your generosity we can make some real magic happen!. Support your favorite online FileMaker community...
FM Forums.com


Click here...


Or a Donation of any amount.


Thanks for your support!

Active Blogs
0 Recent blogs:
People to Post Lately in this Topic
rheinport
LaRetta
TheTominator
comment
mr_vodka
_henry_
FM Forums Advertisers


FusionBB™ Version 3.0 FINAL | ©2003-2010 InteractivePHP, Inc.
Execution time: 0.231 seconds.   Total Queries: 193   Zlib Compression is on.
All times are . Current time is 09:10 AM
Content ©1996-2008 Ocean West Consulting, Inc. All Rights Reserved
Ocean West Consulting, Inc. can not and will not be held responsible for any of the contents in this site.
FM Forums™ is a trademark of Ocean West Consulting, Inc an independent entity, not affiliated with FileMaker Inc.
FileMaker® is a registered trademark of FileMaker Inc.
Top