| | |
Dividing a string
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Oct 2004
Posts: 6
Reputation:
Solved Threads: 0
I have a string that looks for example like this:
"aabbccddeeffgg"
I want to retreive the "ee" or the "cc" value from that string. How can I do that ? The tokenizer is not what I am looking for. I'm looking for the function that allows you to specify that you want the part of the string starting at letter 4 and ending at letter 7.
Please help ;')
"aabbccddeeffgg"
I want to retreive the "ee" or the "cc" value from that string. How can I do that ? The tokenizer is not what I am looking for. I'm looking for the function that allows you to specify that you want the part of the string starting at letter 4 and ending at letter 7.
Please help ;')
•
•
Join Date: Sep 2004
Posts: 84
Reputation:
Solved Threads: 1
Look at the String documentation at:
http://java.sun.com/j2se/1.4.2/docs/api/index.html
specifically at the substring method
http://java.sun.com/j2se/1.4.2/docs/api/index.html
specifically at the substring method
Rentro,
You it it right on. Java actually has a substring function.
See the jdocs for details.
Ed
You it it right on. Java actually has a substring function.
Java Syntax (Toggle Plain Text)
String substring(int beginIndex, int endIndex) // Returns a new string that is a substring of this string.
Ed
•
•
•
•
Originally Posted by Rentro
SUBSTRINGThat was the word I was looking for. Thanks a lot guys .
•
•
•
•
In a world without walls or fences,
What use are Windows and Gates.
•
•
Join Date: Feb 2008
Posts: 28
Reputation:
Solved Threads: 1
•
•
•
•
I have a string that looks for example like this:
"aabbccddeeffgg"
I want to retreive the "ee" or the "cc" value from that string. How can I do that ? The tokenizer is not what I am looking for. I'm looking for the function that allows you to specify that you want the part of the string starting at letter 4 and ending at letter 7.
![]()
Please help ;')
String s = "aabbccddeeffgg";
String s1 = s.substring(4,7);
System.out.println(s1);
it will give the output ccd.
•
•
Join Date: Feb 2008
Posts: 28
Reputation:
Solved Threads: 1
•
•
•
•
but if it's "ee" you want as result:
int pos = firstString.indexOf("ee");
System.out.println(firstString.substring(pos, pos+2));
String s=firstString.substring(8,10);
System.out.println(s);
it will give the output "ee"
but if you would want any arbitary substring then your opinion is correct.
But then if you want an arbitary substring of three or more characters then it would not work, and you would be writing firstString.substring(pos,pos+3) or String.substring(pos,pos+4).
Anyway, thanks for sending me your opinion about this.
![]() |
Other Threads in the Java Forum
- Previous Thread: replace string values with new one?
- Next Thread: ClassNotFoundException with MySql and Netbeans
Views: 4120 | Replies: 11
| Thread Tools | Search this Thread |
Tag cloud for Java
-xlint android animated api apple applet application arguments array arrays automation binary blackberry block bluetooth chat class classes client code component database detection developmenthelp draw eclipse encode error event exception file fractal game givemetehcodez graphics gui helpwithhomework html ide image input integer iphone j2me j2seprojects java javac javaprojects jmf jni jpanel julia lego linux list loop loops mac map method methods mobile netbeans newbie number object online oracle os page print problem program programming project recursion scanner screen server set singleton size sms socket sort sql string swing template test textfields threads time title transfer tree tutorial-sample update windows working







That was the word I was looking for. Thanks a lot guys .