Add \n Every 100 Characters String (AE100CS)

I would like to ask how to parse a String and add a Line break ( \n) every 100 characters. I know that you can parse The String with Regex, but don't know how to proceed later. Can someone help?

You can do something like this:

String str = "....";
String parsedStr = str.replaceAll("(.{100})", "$1\n");

This will replace every 100 characters with the same 100 characters and add a newline at the end.

(.{100})will capture a group of 100 characters. The second $1 will place the contents of the group. Then \nawill be added to the 100 characters that were just matched.


Post a Comment

Previous Next

نموذج الاتصال