Question on TRIM function

  • Thread starter Thread starter mwazir
  • Start date Start date
M

mwazir

Can someone please explain this to me

Dim str As String = Chr(12)
Debug.WriteLine(str) ' Output shows the line feed junk character

Dim iLen As Integer = str.Trim.Length
Debug.WriteLine(iLen) ' Output window shows 0

Dim iLenNoTrim As Integer = str.Length
Debug.WriteLine(iLenNoTrim) ' Output window shows 1

I thought Trim removes all leading and trailing spaces. I didnt understand
why Trim removes CHR(12).
CHR(12) is a line feed character

TIA
 
mwazir said:
Can someone please explain this to me

Dim str As String = Chr(12)
Debug.WriteLine(str) ' Output shows the line feed junk
character

Dim iLen As Integer = str.Trim.Length
Debug.WriteLine(iLen) ' Output window shows 0

Dim iLenNoTrim As Integer = str.Length
Debug.WriteLine(iLenNoTrim) ' Output window shows 1

I thought Trim removes all leading and trailing spaces. I didnt
understand why Trim removes CHR(12).
CHR(12) is a line feed character

Have a look at the Trim documentation (the one without args): All chars are
removed where char.IsWhiteSpace returns True. See char.IsWhitespace docs on
what chars are "white spaces".


--
Armin

How to quote and why:
http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
 
Hi

I do not know if you use ms.visualbasic...Trim or String.Trim. I'm not sure about ms.visualbasic...Trim
but System.String.Trim removes all white spaces. White spaces include characters like tab formfeed (chr(12)
cariage return (13) line feed (10) and so on.

Hope it help

Greating

Ras Alhague
 
I am using System.String.Trim

Thanks for your response. I was under the impression that its only the
trailing and leading spaces.

Regards
--
Wazir


Ras Alhague said:
Hi,

I do not know if you use ms.visualbasic...Trim or String.Trim. I'm not
sure about ms.visualbasic...Trim,
but System.String.Trim removes all white spaces. White spaces include
characters like tab formfeed (chr(12))
 
* "Armin Zingler said:
Have a look at the Trim documentation (the one without args): All chars are
removed where char.IsWhiteSpace returns True. See char.IsWhitespace docs on
what chars are "white spaces".

'Char.IsWhiteSpace(Chr(12))' returns 'True' on my system.
 
* "Armin Zingler said:
Yes, that's why it is removed.

Ooops. While reading your post I forgot that length actually /was/ 0
after trimming...
 
Back
Top