Page 1 of 1

Remove tabs and empty lines

Posted: Fri Aug 07, 2009 2:55 pm
by ConvertFromOldNGs
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?

Re: Remove tabs and empty lines

Posted: Fri Aug 07, 2009 2:55 pm
by ConvertFromOldNGs
by Murray Symon >> Wed, 1 Mar 2006 20:21:14 GMT

No, you could use a simple foreach or while loop. I suggest you check out String::scanWhile() & String::scanUntil(), they may be of help.

--
Murray.

Re: Remove tabs and empty lines

Posted: Fri Aug 07, 2009 2:55 pm
by ConvertFromOldNGs
by Darrell Duniam >> Wed, 1 Mar 2006 20:30:34 GMT

Try something like the attached method we have on the String primitive.

regards,
darrell.

Re: Remove tabs and empty lines

Posted: Fri Aug 07, 2009 2:55 pm
by ConvertFromOldNGs
by Patwos >> Thu, 2 Mar 2006 1:29:53 GMT

I'll assume that what you want to achieve is the removal of leading and trailing white space characters, such as Space, Tab, Cr, Lf etc. (Mentioning trimBlanks in your question is suggestive that this is what you are trying to achieve rather than the removal of all these characters from a given string.)

You may find the following a useful method to add to your String primitive. It uses the Jade supplied String::scanWhile and String::reverse methods, which execute as external methods, to help improve its efficiency when dealing with large strings.

If you require more flexibility, you could pass the whiteSpace characters in as a parameter. I've used a local constant in this sample code.

Hope that helps,
Pat.
__________________________________________________________

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;

Re: Remove tabs and empty lines

Posted: Fri Aug 07, 2009 2:55 pm
by ConvertFromOldNGs
by Scott >> Wed, 8 Mar 2006 9:42:10 GMT

I decide this method.

Thank your help I work it well.