473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TrimEnd with ToCharArray

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
3 5739
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: huzz | last post by:
How do i get rid of the "OR " (at the end) from this string? I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR " I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' " Many...
7
by: Michael Barnes | last post by:
I have encountered what appears to be a bug in String.ToCharArray, and so far I have not found any mention or discussion about it. I am interested to know if anyone else is encountering this...
3
by: W Akthar | last post by:
Hi I am trying to create a windows service which queries SQL Server on timed intervals and depending on the results send appointments to Outlook. The problem lies when I try to create an...
3
by: ezra88 | last post by:
I'm trying t use these lines below to get "new string = "someone", but it won't work. Instead it just keeps coming back as "someone@domain.com". Is there something weird about there being an "@"...
1
by: tshad | last post by:
I have a string that I am trying to strip the last 2 characters that happen to be a "," and a " ". I am also adding a "<br>" to the end. When I am done I still have the ", " and also the <br>. ...
6
by: Tom McL. | last post by:
I'm trying to move a program that was designed using Visual Studio 2003 and (Visual Basic) into Visual Studio 2005. When it runs I get the following warning in the Error List Window and I'm not...
1
by: pon | last post by:
Hi! Inline attachments (images) doesn't seem to work. I have a html-document that I know works fine. This works fine in another mailing-product for me. Not sure if to use attachment with...
5
by: jwgoerlich | last post by:
Hello group, What is the fastest way to remove line feeds from the end of a string? RegEx was too slow. I am using a for loop (code below), but that seems too cumbersome. Any suggestions...
4
by: bmerlover | last post by:
Hi, I need to read a script file and change the text on the buttons I set. I have the psuedocode in my head, but I'm having trouble putting that into code. I figured out how to seperate B1 from T1...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.