Home arrow static arrow Java Programming [Archive] - indexOf and last indexOf
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - indexOf and last indexOf
This topic has 7 replies on 1 page.

Posts:38
Registered: 7/15/03
indexOf and last indexOf  
Aug 10, 2004 5:14 AM



 
Hi

I have a string strin=1,23,4,5

Can i use the indexodf and last indes\x and then a substring.To spilt the number between the comma.
How do i do that.

Regards
Hari

 

Posts:24,036
Registered: 2/3/03
Re: indexOf and last indexOf  
Aug 10, 2004 5:16 AM (reply 1 of 7)



 
Better to use split().
String[] nums = strin.split(",");
 

Posts:24,036
Registered: 2/3/03
Re: indexOf and last indexOf  
Aug 10, 2004 5:18 AM (reply 2 of 7)



 
If, on the other hand, you need to use substring because it's required in the assignment...

Try to do it on your own, and post if you have a specific question. The problem is for you to work out, so that you will learn from the experience.
 

Posts:38
Registered: 7/15/03
Re: indexOf and last indexOf  
Aug 10, 2004 5:20 AM (reply 3 of 7)



 
i have used tokennizer ...but it does not workI wanted to just now.Whether i can use thsi
 

Posts:38
Registered: 7/15/03
Re: indexOf and last indexOf  
Aug 10, 2004 5:22 AM (reply 4 of 7)



 
it's not a rewuiremnt that i need to use it substing.i saw substring in the API.i just wanted to now how to us it.
 

Posts:24,036
Registered: 2/3/03
Re: indexOf and last indexOf  
Aug 10, 2004 5:26 AM (reply 5 of 7)



 
i have used tokennizer ...but it does not workI wanted
to just now.Whether i can use thsi

Tokenizer works fine. Example:
String str = "1,23,4,5";StringTokenizer tok = new StringTokenizer(str, ",");while (tok.hasMoreTokens()) {    System.out.println(tok.nextToken());}
 

Posts:24,036
Registered: 2/3/03
Re: indexOf and last indexOf  
Aug 10, 2004 5:29 AM (reply 6 of 7)



 
it's not a rewuiremnt that i need to use it substing.i
saw substring in the API.i just wanted to now how to
us it.

[url=http://java.sun.com/j2se/1.4.2/docs/api/java/lang/String.html#substring(int,%20int)]substring[/url]
public String substring(int beginIndex,
int endIndex)

Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex.

Examples:
 "hamburger".substring(4, 8) returns "urge"
"smiles".substring(1, 5) returns "mile"


Parameters:
beginIndex - the beginning index, inclusive.
endIndex - the ending index, exclusive.
Returns:
the specified substring.
Throws:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
 

Posts:38
Registered: 7/15/03
Re: indexOf and last indexOf  
Aug 10, 2004 6:09 AM (reply 7 of 7)



 
thanx a lot
 
This topic has 7 replies on 1 page.