Remove Extra Spaces From A String

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();
}

No comments:

Post a Comment