• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 206
  • Last Modified:

To trim a string value

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
larsan
Asked:
larsan
  • 2
1 Solution
 
objectsCommented:
int dot = s.indexOf(".");
if (dot!=-1)
{
   s = s.substring(0, dot-1);
}
0
 
objectsCommented:
or maybe:

s = s.split("\.")[0];
0
 
larsanAuthor Commented:
The first one works if you put it like this:

s=s.substring(0,dot);

Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now