Remove all whitespace from C# string with regex

前端 未结 7 1595
遇见更好的自我
遇见更好的自我 2020-12-25 10:18

I am building a string of last names separated by hyphens. Sometimes a whitespace gets caught in there. I need to remove all whitespace from end result.

Sample strin

7条回答
  •  孤独总比滥情好
    2020-12-25 10:59

    Below is the code that would replace the white space from the file name into given URL and also we can remove the same by using string.empty instead of "~"

      if (!string.IsNullOrEmpty(url))
              {
               string origFileName = Path.GetFileName(url);
               string modiFileName = origFileName.Trim().Replace(" ", "~");
               url = url.Replace(origFileName , modiFileName );
              }
              return url;
    

提交回复
热议问题