string problem...!!!!

hmm...how 2 separate the contain in the document file that ended with dot into lines.

lets say, in this document we have...

halo how r u. I'm fine. tq.

after using some coding become like this...

halo how r u.

I'm fine.

tq.

i hope u all can help me to solve this problem..thx

[326 byte] By [shadowssssa] at [2007-10-2 6:58:38]
# 1
Have a look at String.split(String regex)Drake
Drake_Duna at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...
# 2
String str=new String("halo how r u. I'm fine. tq.");str=str.replaceAll("\\.",".\n").replaceAll("\\.\n ","\\.\n");The above code should...Any brickbats....login to the forum....
getoraam@gmail.coma at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...
# 3
or you could use StringTokenizer and parse it into multiple tokens.
kilyasa at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...
# 4

If I were you I would just read the whole line into a String (s, for example), then any time I wanted one of those pieces I would say

String piece = s.substring(0, s.instanceOf( '.' ) );

s=s.substring( s.instanceOf('.')+1,s.length);

Note that if the period is at the end of the String or if there's no period in the String this will crash, so it requires a little more work, but I have two minutes to get to class. Note that the above code is untested.

AlexanderTrostorffFincha at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...
# 5
I believe instanceOf should be indexOf.
FuzzyOniona at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...
# 6
> Have a look at String.split(String regex)> > Drakehow to write a split function to split the line..thx
shadowssssa at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...
# 7

is this what you are looking for

String src = "a,b,c,d,e,f,g";

String s[] = src.split(",");

for (int i = s.length - 1; i >=0; i --) {

System.out.println(s[i]);

}

kilyasa at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...
# 8

> is this what you are looking for

>

> > String src = "a,b,c,d,e,f,g";

> String s[] = src.split(",");

>

> for (int i = s.length - 1; i >=0; i --) {

>System.out.println(s[i]);

> }

>

>

but i just wan split the line that ended with dot " . "

if i use a.split( " . " )

it cannot work...

shadowssssa at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...
# 9

> but i just wan split the line that ended with dot "

> . "

You've been given a couple of approaches.

> if i use a.split( " . " )

> it cannot work...

That's because you didn't read the docs closely enough. Split takes a regex.

inputString.split("\\.")

jverda at 2007-7-16 20:27:40 > top of Java-index,Other Topics,Algorithms...