8 Comments

  • Nice tip Royo.... thanks!

  • 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?

  • An easier way would be storing the strings in an array and then call String.Join().

  • 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

  • Use ','.join(arrayOfStrings)

  • 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.



  • 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

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

Comments have been disabled for this content.