How can I remove white-spaces from ASP.NET MVC# output?

后端 未结 4 1907
自闭症患者
自闭症患者 2021-01-31 23:00

How can I remove all white-spaces from ASP.NET MVC 3 output?


UPDATE: I know how can I use string.Replace method or Regular Expressions to remove w

4条回答
  •  心在旅途
    2021-01-31 23:38

    You could use the String.Replace method:

    string input = "This is  text with   ";
    string result = input.Replace(" ", "");
    

    or use a Regex if you want to remove also tabs and new lines:

    string input = "This is   text with   far  too   much \t  " + Environment.NewLine +
                   "whitespace.";
    string result = Regex.Replace(input, "\\s+", "");
    

提交回复
热议问题