Replace Pioneer Home   All Examples   Free Download

 New request --free  RSS: Replace Pioneer Examples

103.Advanced search and replace -- How to add hard returns to limit line length to 40, but without breaking word?

User: editor -- 2008-05-15          << 102  104 >>
Hits: 548
Type: Advanced search and replace   
Search all Advanced search and replace examples
Description:
How to add hard return for a text file, and limit each line to less than 40 characters, and don't break word?
Input Sample:
More than 4.3 million homes collapsed or sustained damage, according to the Chinese Embassy in Washington, and the official death toll from the quake had reached 14,866 by Wednesday evening.
But casualty figures from various cities indicate a higher number of dead.
Output Sample:
More than 4.3 million homes collapsed or
sustained damage, according to the
Chinese Embassy in Washington, and the
official death toll from the quake had
reached 14,866 by Wednesday evening.

But casualty figures from various cities
indicate a higher number of dead.
Answer:
Hint: You need to Download and install "Replace Pioneer" on windows platform to finish following steps.
1. ctrl-o open source file
2. ctrl-h open 'replace' dialog, set 
1) set 'Replace Unit' to Chars
2) set 'Replace Scope' to Line
3) set 'search for pattern': 

4) set 'replace with pattern':

3. click 'Replace' 

Note: 
1. step 1, 3) use 'regular expression', so need to uncheck 'enhanced regular expression'.
2. '.{2,40}( |$)' means 2 to 40 characters followed by a space or line end.
3. $match\n means add a '\n' for each matched text.
Download Script:  scripts/103.rst.zip

Screenshot 1:  Replace_Window


Similar Examples:
How to wrap text by adding return but without breaking words? (63%)
How to remove all duplicated lines without considering the last word? (49%)
How to sort a text file by the length of text in each line? (48%)
How to find all lines in file A that contain words in file B? (47%)
How to add a '*' at the beginning of each line that contains keyword "PASS"? (47%)
How to extract all lines that contain A, but not any of B C D? (47%)
How to remove all lines containing 'test1' and 'test2' but without 'test3'? (47%)
How to extract all lines that contain chem, but not any of org and cn? (45%)

Check Demo of Advanced search and replace
Keywords:
without break  hard  hard return  break  less  length  without  return  space  scope  regular expression line length  word replace return with space  replace return with space  regular expression add space  replace each space by  add a return  length line  regular expression space