Join wMUsers | Blog at wMUsers | Edit my wMUsers Profile | Site Map | Invite your peers | webMethods Jobs | For Employers

Remove Leading Zero's

wMUsers Discussion Forums » Integration Server & Trading Networks » Development Feedback » Archive through November 4, 2002 » Remove Leading Zero's

Author Message
Marco Jongen

Rating: N/A
Votes: 0 (Vote!)

Posted on Friday, May 03, 2002 - 06:59 am:   Print Post

Does anyone have a good solution for removing leading zero's?

I have tried the pub.remove service, but this creates the following, with these values:
inString:
searchString:
replaceString:
useRegex:

inString is +0000123979708900
Result is +123979789

And it is supposed to be +123979708900

Hope anyone can help with this...
Rob Eamon

Rating: N/A
Votes: 0 (Vote!)

Posted on Friday, May 03, 2002 - 11:16 am:   Print Post

Here's Java code that you can adapt to put into a Java service:

 
// Remove leading characters from a string.
//
// @return java.lang.String String with all leading characters specified by paramter 'c' removed
// @param s java.lang.String Source string
// @param c char Leading characters to remove

String trimLeft(String s, char c)
{
if(s == null)
return "";
int len = s.length();
int n = 0;
while(n < len && s.charAt(n) == c)
++n;
return s.substring(n);
}


If your string starts with a sign, you'll need to remove it before calling this service and then put it back after you get the trimmed string.
Michael Herzog

Rating: N/A
Votes: 0 (Vote!)

Posted on Friday, May 03, 2002 - 11:30 am:   Print Post

If you can remove the sign, you can also just wack this string into an integer:

String s_no_sign = "0000123979708900";
Long n = new Long(s_no_sign);
Rob Eamon

Rating: N/A
Votes: 0 (Vote!)

Posted on Friday, May 03, 2002 - 11:37 am:   Print Post

My previous post with the Java code for trimming leading characters didn't get formatted correctly in the e-mail. Please visit the discussion board to see the full post.
Rob Eamon

Rating: N/A
Votes: 0 (Vote!)

Posted on Friday, May 03, 2002 - 12:11 pm:   Print Post

Here's a way to do it without needing to strip the leading sign:

java.text.DecimalFormat df = new java.text.DecimalFormat();
df.setPositivePrefix("+");
Number n = df.parse("+000012397908900");
return n.toString();
Erik Versteijnen

Rating: N/A
Votes: 0 (
Vote!)

Posted on Friday, May 03, 2002 - 03:53 pm:   Print Post

Just use 'pub.string:replace':

inString: +0000123979708900
searchString: ^\+0+
replaceString: +
useRegex: true
Rob Eamon

Rating: N/A
Votes: 0 (Vote!)

Posted on Friday, May 03, 2002 - 04:31 pm:   Print Post

I always forget about using regular expressions! Awsome solution!
viv (Unregistered Guest)
Posted on Thursday, September 29, 2005 - 02:22 am:   Print Post

I tried the reg exp to remove just the trailing zeros and failed, can you suggest how to remove just the trailing '0's
Puneet Verma
Intermediate Member
Username: puneetverma


Post Number: 48
Registered: 12-2003

Rating: N/A
Votes: 0 (Vote!)

Posted on Thursday, September 29, 2005 - 04:06 am:   Print Post

Viv,
You need to use the $ after the expression to remove the trailing zeroes.

inString: 12345000
searchString: 0+$
replaceString:
useRegex: true

HTH..

Thanks,
Puneet Verma

 

 

Add Your Message Here
Post:
Username: wMUsers Members: Use your username/password to increase your "Total Posts" ranking and link your profile.

Non-members: Use your full name as a username.
Password:
Email:
Options: Enable HTML code in message
Automatically activate URLs in message
Action:


Advertise at wMUsers

Check out our Frappr!




© All Rights Reserved, 2001-2005.

Script Execution Error

Your discus.conf file could not be opened.
Error:  Open discus.conf: No such file or directory
Script: dummy.cgi
OS:     linux
Perl:   5.008008
Descr:  No such file or directory
Discus: 4.0

Read documentation in the Support Center
Also try your Program Diagnostics