How to remove escape sequences from stream

前端 未结 5 1412
后悔当初
后悔当初 2021-01-14 15:48

is there an quick way to find(and remove) all escape sequences from a Stream/String??

5条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-14 16:17

    If you're going for fewer lines of code:

    string inputString = "\ncheese\a";
    char[] escapeChars = new[]{ '\n', '\a', '\r' }; // etc
    
    string cleanedString = new string(inputString.Where(c => !escapeChars.Contains(c)).ToArray());
    

提交回复
热议问题