tags:

views:

50

answers:

3

Hi how can i read one line from string ??? i have string like this :

hello ; boy ; sun

welcome;google;pink

how can i read first line only ? thanks

+1  A: 
String originalString="hello ; boy ; sun\nwelcome;google;pink";
String firstLine=originalString.substring(0,originalString.indexOf('\n'));
BlaXpirit
A: 

See this previous question, but I like this solution better:

final InputStreamReader r = new InputStreamReader( new ByteArrayReader( string.getBytes() ) );
dj_segfault
What is this? Have you even read the question?
BlaXpirit
Uh, yeas. I was giving an alternative way of doing it by reading the string like a stream. I realize J2ME doesn't have StringReader, so this is another way of doing it.
dj_segfault
How did this guy get so much rep!?
BlaXpirit
If you don't think my solution is a good one, then that's fine, but I presented an alternate way of reading a string line by line in J2ME, as if it was a file. What's your problem? Why don't you think my answer is relevant? because I didn't spell out the loop to read from the stream? I thought that was kinda obvious.
dj_segfault
+1  A: 

be aware that some applications actually use \r\n instead of \n to indicate new lines

Mahdi Hijazi