Solved

To trim a string value

Posted on 2004-10-13
3
197 Views
Last Modified: 2010-04-01
Hi!

I have a string value that can look somewhat like this:
"410.13456"
"1024.7940"
or something like that.

What I want to do is, if there's a "." in the string, remove everything behind it. Ie. "410.13456" will become "410".

How do I do this the simplest way possible.

Regards,
David
0
Comment
Question by:larsan
  • 2
3 Comments
 
LVL 92

Accepted Solution

by:
objects earned 500 total points
ID: 12296308
int dot = s.indexOf(".");
if (dot!=-1)
{
   s = s.substring(0, dot-1);
}
0
 
LVL 92

Expert Comment

by:objects
ID: 12296313
or maybe:

s = s.split("\.")[0];
0
 

Author Comment

by:larsan
ID: 12296881
The first one works if you put it like this:

s=s.substring(0,dot);

Thanks!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
java cyclic graphs 15 210
some methods private some are not 8 212
squirrelPlay java challenge 40 158
Use tracing facilities in your browser steps 2 118
This article outlines why you need to choose a backup solution that protects your entire environment – including your VMware ESXi and Microsoft Hyper-V virtualization hosts – not just your virtual machines.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question