Remove Extra Spaces From A String

January 5, 2014 at 3:27 PMAdmin

 

Use the following extension method to remove the extra spaces ( in the middle ) from a desired string , its easy right :)



public static string RemoveWhiteSpace(this string mStr)

{

    string mRet = mStr.Trim().Replace("  "" ");

    while (mRet.Contains("  "))

mRet = mRet.Replace("  "" ");

 

    return mRet.Trim();

 

}

Posted in: .NET | IT

Tags: