TrimEnd() Vs. SubString()

My blog has moved.
You can view this post at the following address:
http://www.osherove.com/blog/2004/4/29/trimend-vs-substring.html
Published Friday, April 30, 2004 1:59 AM by RoyOsherove
Filed under:

Comments

Thursday, April 29, 2004 11:16 PM by Darren Neimke

# re: TrimEnd() Vs. SubString()

Nice tip Royo.... thanks!
Friday, April 30, 2004 2:28 AM by TrackBack

# re: Handling the comma. Period.

Friday, April 30, 2004 8:01 AM by Nicole Calinoiu

# re: TrimEnd() Vs. SubString()

TrimEnd() will remove _all_ occurrences from the end of the string, so it's not a particularly effective general solution since the string representation of the last item in the source collection may contain a trailing comma. Granted, within-item delimiter occurrences are likely to cause even worse problems than this, but why go looking for trouble when a cleaner alternative exists?
Friday, April 30, 2004 8:23 AM by Daniel Turini

# re: TrimEnd() Vs. SubString()

An easier way would be storing the strings in an array and then call String.Join().
Friday, April 30, 2004 9:39 AM by TrackBack

# .NET Happenings #29

Friday, April 30, 2004 10:17 AM by Jim Bolla

# re: TrimEnd() Vs. SubString()

nice. i like this methodology. mine is usually to append a *leading* comma and then do s = s.Remove(0, 1) when the loop has completed
Friday, April 30, 2004 10:38 AM by Greg

# re: TrimEnd() Vs. SubString()

Use ','.join(arrayOfStrings)
Friday, April 30, 2004 2:42 PM by Nice

# re: TrimEnd() Vs. SubString()

Nice technique :)
Have converted the snippet for PHP coders:
http://www.mr-andersen.no/index.php?id=0ecc77

Thomas Andersen
Friday, June 11, 2004 1:30 AM by Guy S.

# re: TrimEnd() Vs. SubString()

10x Roy
I saw this tips weeks ago and I remember it is waiting for me.
Right now I search in google - +weblogs remove last delimiter +roy and guess what I got.

Tuesday, September 19, 2006 2:55 AM by Mohammad Sallout

# re: .TrimEnd() Vs. SubString()

I think .TrimEnd() is better "In this case" because the compiler will go from the end directly instead of going from start to end. Java programers ask "Is this the best .net can do? Trim a character?" the answer is NO, you even can trim String. this is a sample code for clarify the way. //The code will end trim the String ", " char[] trim_str = {',',' '}; myString = myString.TrimEnd(trim_str); I hope it will be useful
Tuesday, March 20, 2007 12:51 PM by sokka

# re: TrimEnd() Vs. SubString()

I have a problem in your design. I use Netscape.