Trim whitespace (start and end) of string

Last post 12-17-2007 5:24 PM by mr.aspdotnet. 3 replies.

Sort Posts:

  • Trim whitespace (start and end) of string

    12-17-2007, 5:06 PM
    Just wondering how you can trim the whitespace of a string for the start and end of it.

     
    e.g.    "   My String   "

     

    Thanks!
     

    Success comes to those who prepare well and put in effort.
  • Re: Trim whitespace (start and end) of string

    12-17-2007, 5:20 PM
    Answer
    • Participant
      1,917 point Participant
    • interwanderer1
    • Member since 04-03-2005, 3:29 PM
    • Belgium
    • Posts 395

    nothing more then string.trim(); put the string value in a string variable.

    greets,

     Erdem

    see my latest project at www.SocialTomorrow.com.
  • Re: Trim whitespace (start and end) of string

    12-17-2007, 5:24 PM
    Answer
    • Member
      48 point Member
    • mark836
    • Member since 12-11-2007, 2:32 PM
    • Posts 164

    Here are the methods available to you

     

    public string Trim(params char[] trimChars);

    public string Trim();

    public string TrimStart(params char[] trimChars);

    public string TrimEnd(params char[] trimChars);

  • Re: Trim whitespace (start and end) of string

    12-17-2007, 5:24 PM
    Answer
    • Contributor
      2,259 point Contributor
    • mr.aspdotnet
    • Member since 08-11-2007, 5:57 AM
    • Manchester, UK
    • Posts 393

    Hi,

    try this

    String myString = " My String ";

    myString.Trim(' ');

    Regards

    Don't forget to click (Mark as Answer) on the post that helped to solve your problem.
Page 1 of 1 (4 items)