regex - Add line break after every 60 characters in String for Java -


this question has answer here:

suppose string this:

string msg = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz" 

i want add or append line break (a carriage return) after every 60 characters either through looping or regex (regex cooler).

you in java :

string msg = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz..."; string updatedmsg = msg.replaceall("(.{60})", "$1\r"); 

this replace every 60 characters same 60 characters , add carriage return @ end.

the (.{60}) capture group of 60 characters. $1 in second put content of group. \r appended 60 characters have been matched. have @ http://www.regular-expressions.info/java.html


Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -