Solved

To trim a string value

Posted on 2004-10-13
3
198 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
hashcode is calculated on the basis of value object 2 118
if statement not resolving in my code 5 55
maven project jars 7 55
how to hide hide popup page refresh second time? 10 142
This article describes my battle tested process for setting up delegation. I use this process anywhere that I need to setup delegation. In the article I will show how it applies to Active Directory
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…

860 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