I have such a text for example:
"A01+B02+C03+D04+E05+F06+G07+H08+I09+J10+K11+L12+M13+N14+O15+P16"
I would like to add a space after each fourth '+' sign.
This is because if the text is too long in the grid's cell in my page, then it's simply cut off. So I'm thinking to simply wrap the string before binding the data to the grid.
I've played around with several string methods, like getting the IndexOf and the adding a space with Insert, or using a StringBuilder to make a completely new string out of the original one, but I just can't get the final solution running.
Any help would be appreciated. Thanks.
Use a regex:
Pattern pattern = Pattern.compile("([^+]*\\+){4}");
Matcher matcher = pattern.matcher(str);
matcher.replaceAll("\1 ");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With