I have a text area wherein i have limited the user from entering more that 15 characters in one line as I want to get the free flow text separated into substrings of max limit 15 characters and assign each line an order number. This is what I was doing in my java class:
int interval = 15;
items = new ArrayList();
TextItem item = null;
for (int i = 0; i < text.length(); i = i + interval) {
item = new TextItem ();
item.setOrder(i);
if (i + interval < text.length()) {
item.setSubText(text.substring(i, i + interval));
items.add(item);
}
else {
item.setSubText(text.substring(i));
items.add(item);
}
}
Now it works properly unless the user presses the enter key. Whenever the user presses the enter key I want to make that line as a new item having only that part as the subText.
I can check whether my text.substring(i, i + interval
) contains any "\n"
and split till there but the problem is to get the remaining characters after "\n"
till next 15 or till next "\n"
and set proper order and subText.