Question on TRIM function

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
 
A

Armin Zingler

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
 
G

Guest

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
 
M

mwazir

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))
 
H

Herfried K. Wagner [MVP]

* "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.
 
H

Herfried K. Wagner [MVP]

* "Armin Zingler said:
Yes, that's why it is removed.

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

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top