Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

string delimitation 2

Status
Not open for further replies.

MikeT

IS-IT--Management
Feb 1, 2001
376
US
I have this string: 3,999
I need to extract all the characters before the comma, and turn them into a number, and the same for all the characters behind the comma. The amount in front of the comma and behind can vary.

Thanks!
 
hi you can do this

test = 3,999

position = test.IndexOf(",")

firststring = test.substring(0,position)
secondstring = test.substring(position)

hope that helps.

Hui Emagine Solutions, Inc.
 
the functions are indexOf
and subString

notice small case then big case...this is generic java functions...

indexOf -> finds the position of a character and returns back an integer.

subString -> breaks the string into smaller strings (for example test = abcdef
test.subString(0,2) will return back the first 3 characters...i think it's starts at 0, i might be wrong, haven't look at the reference on for awhile, this is all coming out of my head. If you just put 1 argument it will return the first position and all the rest of it along the way.

Hope this helps,
Hui
Emagine Solutions, Inc.
 
I think split is a better choice:

test = "3,999"

tstsplit = test.split(",")

string1 = tstsplit[0]
string2 = tstsplit[1]

just my opinion, as only one function call is needed jared@eae.net -
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top