tags:

views:

333

answers:

1
TextUtils.StringSplitter splitter = new TextUtils.SimpleStringSplitter('\n');
 splitter.setString(tweetMessage);
 tweetMessage = "";
 for (String s : splitter) 
 {
  Log.v(getClass().getSimpleName(), "Spliter :: "+ s);
  tweetMessage +=s;
 }

But this shows up the newline characters as Squares how do I get Rid of that

A: 

The characters you're seeing as squares probably aren't '\n' ('\u000A') characters.

If you're seeing a multiple lines in your output then it's possible that multiple characters are being used to split the lines. It might be '\r\n' but it could be something else.

Your best bet is to use a debugger to check exactly what the String contains before you split it. Or you could add some debug code like so:

for (int u : tweetMessage.toCharArray()) {
    Log.v(getClass().getSimpleName(), String.format("\\u%04X",u));
}

If you see \u000D \u000A then your lines are separated by "\r\n". This means you can't use a SimpleStringSplitter to split the string since that will only split on a single character.

If you don't want to parse the string manually, you could use the String.split() method:

for (String s : tweetMessage.split("\r\n") {
    //do something with s
}
Dave Webb
Ya its showing '\u000A' but before this its showing '\u000D'
y ramesh rao
Have updated the answer to give you some more help. If this solves your problem please accept the answer by clicking the tick. Also, you should revisit your old questions and accept some answers there too.
Dave Webb