I want to split a string Like 'Rupees Two Hundred Forty One and Sixty Eight only' when its length is at 35, I want to split this string in 2. I tried this code to split the string.
String text = "Rupees Two Hundred Forty One and Sixty Eight only";
List<String> parts = new ArrayList<>();
int length = text.length();
for (int i = 0; i < length; i += 35) {
parts.add(text.substring(i, Math.min(length, i + size)));
but the output is like this.
[Rupees Two Hundred Forty One and Si, xty Eight only]
But I want to split the string like this.
[Rupees Two Hundred Forty One and, Sixty Eight only]
There is no cut word when splitting the string. The string varies every time according to the bill amount.