Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Trim
Mon, Jul 9 2012 11:23 AMPermanent Link

Matthew Jones

A suggestion for enhancing the "Trim" function: Remove #13 characters too.

On Delphi, my server prepares a CSV file using TStringList, and then sends the
MyList.Text to the EWB client. That then takes the list to bits a line at a time,
and uses code like this:

 xCSVList := TStringList.Create;
 xCSVList.LineSeparator := ',';
 //
 xCSVList.Text := szStudentLine;
 for nDataLoop := 0 to xCSVList.Count - 1 do
 begin
   DataSet1.Columns[nDataLoop].AsString := Trim(xCSVList[nDataLoop]);
 end;

Now, the issue here is that the last item will have a #13 character on the end,
because the Delphi code uses CR/LF (#13#10) characters for each line, and the
browser is using just #10. Trim is supposed to (in Delphi) remove whitespace, which
should be spaces, tabs, and superfluous #13 characters I would suggest. It's not
critical, but it would be a nice way to sanitise data that comes from other
systems.
 
/Matthew Jones/
Mon, Jul 9 2012 12:54 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< A suggestion for enhancing the "Trim" function: Remove #13 characters
too.  >>

Hmm, I'll have to think about this.  I might just add a separate
TrimWhiteSpace() function that does this because the Trim() function
currently only looks at the TrimChar (default ' ') passed in to the
function.

Thanks,

Tim Young
Elevate Software
www.elevatesoft.com
Tue, Jul 10 2012 4:13 AMPermanent Link

Matthew Jones

Hmm, so I could do Trim(MyString, #13)? Perhaps supporting multiple characters
would solve it? I wonder though if this isn't just something that would be "nice to
have the framework sort" rather than coding for that special situation. I only
noticed this because I was looking to remove a trailing " and it wasn't being
removed. It was an invisible character that was causing it, which is never easy to
find.

/Matthew Jones/
Tue, Jul 10 2012 1:21 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Matthew,

<< Hmm, so I could do Trim(MyString, #13)? >>

Yes.

<< Perhaps supporting multiple characters would solve it? >>

I could probably do an overloaded version that accepted character arrays
also, and that would probably resolve the multiple character issue.

Tim Young
Elevate Software
www.elevatesoft.com
Image