www.fireflysoftware.com

Search and Replace Carriage Returns


Although, lines can be inserted into the text stream by inserting carriage return / linefeed pairs, (#0d#0a) it is not possible to delete lines using this approach since carriage return / linefeed pairs cannot actually be found within input lines of text.* Fortunately, there's a way around this by using the JoinLines filter. This technique can be used to replace not only the strings that are adjacent to carriage return / linefeeds, but also the carriage return / linefeeds themselves. For example, the following pipe uppercases all occurrences of the word "the" that are located at the end of a line, (i.e. those that are adjacent to a carriage return / linefeed):

AppendStr '$'
JoinLines
ReplStr 'the$' 'THE$' '$' '#0d#0a'

Given the text,

now is the time
for all good men
to come to the
aid of their country.

The pipe outputs:

now is the time
for all good men
to come to THE
aid of their country.

Notice that only one word "the" is uppercased but the other two, (one embedded in the word "their") are left unchanged as they are not at the end of a line. This technique is also demonstrated in the sample pipe, "Delete Double Carriage Returns.ttp" in the "Sample Pipes" folder beneath the TEXTools installation folder.


* In a text file, carriage return / linefeed pairs are used to separate lines and are thus not considered part of the text.

 

[Home] [Contact Us] [Downloads] [Purchase/Register]

Copyright © 2005 Firefly Software