How to Remove white space from the beginning or end of a string?

How to Remove white space from the beginning or end of a string?

Asked on October 26, 2018 in String.
Add Comment


  • 3 Answer(s)

        Codes for removing whitespace:

    String.Trim() to trim all the white-spaces from start and end of a string:

    " A String ".Trim() -> "A String"
    

    String.TrimStart() will trim all white-spaces from the start of a string:

    " A String ".TrimStart() -> "A String "
    

    String.TrimEnd() will trim all white-spaces from the end of a string:

    " A String ".TrimEnd() -> " A String"
    
    Answered on October 26, 2018.
    Add Comment

    Use

    String.Trim()
    
    

    to removes all whitespace from the beginning to end of a string. For remove whitespace inside a string, or normalize whitespace, use a Regular Expression.

    Answered on October 26, 2018.
    Add Comment

    For getting a trimmed output use this code:

    string a = " wikitechy ";
    
    string trimmed = a.Trim();
    
    
    Answered on October 26, 2018.
    Add Comment


  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.