从字符串中删除空白字符

时间:2011-06-23 19:55:55

标签: c# asp.net string replace

字符串变量将值存储为... careteam order 4-26-11.csv

我需要在c#中修剪值..就像careteamorder4-26-11.csv一样 - 删除空格..!

如何删除字符串变量中的空格?

2 个答案:

答案 0 :(得分:44)

string trimmed = "careteam order4-26-11.csv".Replace(" ", string.Empty);

答案 1 :(得分:0)

    public string RemoveSpaceAfter(string inputString)
    {
        try
        {


            string[] Split = inputString.Split(new Char[] { ' ' });
            //SHOW RESULT
            for (int i = 0; i < Split.Length; i++)
            {
                fateh += Convert.ToString(Split[i]);
            }
            return fateh;
        }
        catch (Exception gg)
        {
            return fateh;
        }
    }