by Scott >> Wed, 1 Mar 2006 11:44:22 GMT
It possible trimBlanks use remove tabs and empty lines.
Is so, please advise the technique?
Code: Select all
trimWhiteSpace() : String;
constants
WhiteSpaceCharacters : String = Cr & Lf & Tab & " " ;
vars
startPos : Integer ;
endPos : Integer ;
str : String ;
begin
if self = null then
return null ;
endif;
// Find the first non-white-space character
startPos := 1 ;
self.scanWhile( WhiteSpaceCharacters, startPos );
// Does string contain nothing but white space? If so, return null
if startPos = 0 then
return null ;
endif;
// Now find the last non-white-space character, reversing the string so we can use scanWhile again for efficiency
str := self.reverse;
endPos := 1 ;
str.scanWhile( WhiteSpaceCharacters, endPos );
endPos := self.length - endPos + 1 ;
// Create the final string trimmed of leading and trailing whitespace
str := self[startPos : endPos - startPos + 1 ];
return str ;
end;
Return to “Tips and Techniques”
Users browsing this forum: No registered users and 7 guests