By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,035 Members | 1,543 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,035 IT Pros & Developers. It's quick & easy.

TrimEnd with ToCharArray

P: n/a
Hi,
Why am I getting unexpected results here? This is VB.NET 2005 from my
Immediate Window. See 2nd line.

?"test.trim".TrimEnd("trim".ToCharArray)
"test."
?"test.trim".TrimEnd(".trim".ToCharArray)
"tes"
?"test.trim".TrimEnd("t.trim".ToCharArray)
"tes"
?"test.trim".TrimEnd("st.trim".ToCharArray)
"te"

Any ideas if this is a bug or what?
Apr 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
this looks correct. you told it to trim off all trailing characters the the
array ".trim"
every character in "test.trim" after "tes" is in the array of characters to
trim.
You would get the same thing if your string was
"test.trimmiiiirrrtt.t.t."
If youre trying to trim a certain string off the end dont use trim.
Maybe try EndsWith and SubString
"JohnMSyrasoft" wrote:
Hi,
Why am I getting unexpected results here? This is VB.NET 2005 from my
Immediate Window. See 2nd line.

?"test.trim".TrimEnd("trim".ToCharArray)
"test."
?"test.trim".TrimEnd(".trim".ToCharArray)
"tes"
?"test.trim".TrimEnd("t.trim".ToCharArray)
"tes"
?"test.trim".TrimEnd("st.trim".ToCharArray)
"te"

Any ideas if this is a bug or what?
Apr 24 '07 #2

P: n/a
JohnMSyrasoft <Jo***********@discussions.microsoft.comwrote:
Why am I getting unexpected results here? This is VB.NET 2005 from my
Immediate Window. See 2nd line.

?"test.trim".TrimEnd("trim".ToCharArray)
"test."
?"test.trim".TrimEnd(".trim".ToCharArray)
"tes"
?"test.trim".TrimEnd("t.trim".ToCharArray)
"tes"
?"test.trim".TrimEnd("st.trim".ToCharArray)
"te"

Any ideas if this is a bug or what?
Not a bug, just a mistaken understanding of what TrimEnd does. The char
array parameter you provide is a *set* of characters to trim. It
removes the t at the end of test because it's in the set.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Apr 24 '07 #3

P: n/a
Thanks to both responses. I didn't properly understand that it was a set of
characters. I thought that ordered mattered in some way but now I
understand. Thanks very much for your help.

"JohnMSyrasoft" wrote:
Hi,
Why am I getting unexpected results here? This is VB.NET 2005 from my
Immediate Window. See 2nd line.

?"test.trim".TrimEnd("trim".ToCharArray)
"test."
?"test.trim".TrimEnd(".trim".ToCharArray)
"tes"
?"test.trim".TrimEnd("t.trim".ToCharArray)
"tes"
?"test.trim".TrimEnd("st.trim".ToCharArray)
"te"

Any ideas if this is a bug or what?
Apr 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.