My code in java and I have a long text (Maximum 500 characters) and I want to do a kind of Segmentation on this text, and in every segment I want only 6 characters for example: this is an example text:
String fullText = "Syria officially known as the Syrian Arab Republic, is a country in Western Asia...";
and I want this result:
segment1: Syria
segment2: offici
Segment3: ally k
Segment n: ……
I have tried with for loop but I did not reach to my goal.. and also I have an error
java.lang.StringIndexOutOfBoundsException: length=67; regionStart=65; regionLength=5
This is my code:
String msg = fullText;
for(int i=-1 ; i <= fullText.length()+1; i++){
int len = msg.length();
text = new StringBuilder().append(msgInfo).append(msg.substring(i, i + 6)).toString();
msg = new StringBuilder().append(msg.substring(i +5, len)).toString();
LogHelper.d(TAG, "teeeeeeeeeeeeext:"+i +" .."+ text);
}
How i can do this segmentation correctly? Thankyou!