What I am trying to accomplish here is to trim the String after the word is finished. But also trying to stay efficient, and not use StringArray.length
since some String are longer than 2k characters.
int len = 140;
String str = Html.fromHtml((cureent.getTextContent().replaceAll("\n",""))).toString();
char[] StringArray;
StringArray = str.toCharArray();
for(int Index=140;Index < 150;Index++) {
Log.d("Current Letter",String.valueOf(StringArray[Index]));
if (String.valueOf(StringArray[Index]).equals(" ")){
Log.d("Found E at" + String.valueOf(Index) ,"The Value is " + String.valueOf(StringArray[Index]));
}
item.setDescription(Html.fromHtml(cureent.getTextContent()).toString().replaceAll("\n", "").trim().substring(0,Index).replace((char) 65532, (char) 32).trim());
}
E in my log Stands for Empty space
here is a bit of what the log returns.
2018-05-17 17:46:47.492 2616-2653/com.apo.rssredaer D/Found E at148: The Value is
2018-05-17 17:46:47.495 2616-2653/com.apo.rssredaer D/Found E at141: The Value is
2018-05-17 17:46:47.498 2616-2653/com.apo.rssredaer D/Found E at145: The Value is
But I cant get it to trim right after the word. I still get words trimmed in the middle or whatever position they are trimmed at
Example. lets say I have this string that I got from My rss.
And so, in honor of the antechinus’ tragic death, we give you a small sampling of the for the example I'll use 14 instead of 140 as my counter, and I'll count from 0. Trimming it will return to me:
"And so, in hon"
But whenever this is the case. I want it to keep going and trim it at
"And so, in honor"
hope I make some sense.
OK try this:
int position = 0; //create a pointer
for (int index = 140; index < 150; index++) {
if (str.charAt(index).equals(" ")) {
position = index;
break; //stop the loop when you find a space
}
}
//create a substring from 0 to Index
item.setDescription(Html.fromHtml(str.substring(0, position));