The Artima Developer Community
Sponsored Link

.NET Buzz Forum
TrimEnd() Vs. SubString()

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Roy Osherove

Posts: 1807
Nickname: royo
Registered: Sep, 2003

Roy Osherove is a .Net consultant based in Israel
TrimEnd() Vs. SubString() Posted: Apr 30, 2004 5:38 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Roy Osherove.
Original Post: TrimEnd() Vs. SubString()
Feed Title: ISerializable
Feed URL: http://www.asp.net/err404.htm?aspxerrorpath=/rosherove/Rss.aspx
Feed Description: Roy Osherove's persistent thoughts
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Roy Osherove
Latest Posts From ISerializable

Advertisement
Many developers have had to write a loop that writes out a comma separated value list. There's always the trick of how you make that last comma get removed from the end of that string. Usually, at the end of the loop, many developers will do something like this to remove the last char in the string:
 
out = out.Substring( 0, out.LastIndexOf( ',' )
 
However, there's a cleaner way to accomplish this task:
 
out = out.TrimEnd(',')
 
TrimeEnd can receive a char array so you can remove any unwanted chars from the end easily. The code is also more readable. And yes, there's a TrimStart() to match that function.

Read: TrimEnd() Vs. SubString()

Topic: I know that movies based on books are often a disappointment... Previous Topic   Next Topic Topic: What does it mean to be an MVP?

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use