Removing hidden characters from within strings

前端 未结 8 1290
既然无缘
既然无缘 2020-12-01 10:37

My problem:

I have a .NET application that sends out newsletters via email. When the newsletters are viewed in outlook, outlook displays a question mark in place

8条回答
  •  庸人自扰
    2020-12-01 10:54

    You can remove all control characters from your input string with something like this:

    string input; // this is your input string
    string output = new string(input.Where(c => !char.IsControl(c)).ToArray());
    

    Here is the documentation for the IsControl() method.

    Or if you want to keep letters and digits only, you can also use the IsLetter and IsDigit function:

    string output = new string(input.Where(c => char.IsLetter(c) || char.IsDigit(c)).ToArray());
    

提交回复
热议问题