Results 1 to 6 of 6
- 04-02-2010, 04:56 PM #1
Member
- Join Date
- Mar 2010
- Posts
- 49
- Rep Power
- 0
Please help me with Split method> String
HI , all:confused::confused:
please help me,,
i want to know how does split()method in String class works..
Coz i want to create a new split method that returns an array of strings with delimiters,
for example ("ab$sc$11$" , "$") >>returns an array that contains
ab,$,sc,#,11,$
please help with code ,,or with the alogarithm at least,,
I dont know how to start !!!
please Help !!
- 04-02-2010, 06:18 PM #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 14,422
- Blog Entries
- 7
- Rep Power
- 29
If that delimeter is always just a single character have a look at the two argument split( ... ) method. You still have to insert those delimeters in the resulting array yourself though. Pay special attention when that delimeter occurs at the end of the original String. The two argument split( ... ) method can tell you if that is so.
kind regards,
Jos
- 04-02-2010, 06:52 PM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Simply I think you can count the number of element in return array and as Jos says pay attention on delimiters at the end of the original string.
- 04-02-2010, 07:07 PM #4
Member
- Join Date
- Mar 2010
- Posts
- 49
- Rep Power
- 0
Can u check please ?? am i on the right direction ??
String string = "John-is-very-angry";
String []arr;
String s;
int j;
int x;
int i =0;
int j = 0;
while(i < string.length()){
if((string.indexOf('-', i ) != -1)){
x = string.indexOf('-', i );
s = string.substring(i, x);
i = x;
System.out.println(s);
i++;}
}
- 04-02-2010, 07:09 PM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
You define variable j twice in wrong way.
Java Code:int j; int x; int i =0; int j = 0;
Java Code:int j = 0; int x; int i =0;
- 04-02-2010, 07:15 PM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,370
- Blog Entries
- 1
- Rep Power
- 26
Did you run your code? If so what happen?
Java Code:while (i < string.length()) {
Java Code:while (i < string.length()) {
Similar Threads
-
reverse string split
By Fittersman in forum Advanced JavaReplies: 4Last Post: 03-09-2010, 01:29 AM -
string split
By gisler in forum New To JavaReplies: 6Last Post: 12-17-2009, 03:23 PM -
split method question
By Chasingxsuns in forum New To JavaReplies: 3Last Post: 11-19-2009, 08:19 PM -
How to split a String using split function
By Java Tip in forum java.langReplies: 4Last Post: 04-17-2009, 09:27 PM -
How to split a String using split function
By JavaBean in forum Java TipReplies: 0Last Post: 10-04-2007, 10:32 PM
Bookmarks