How to remove characters from a string, except those in a list

后端 未结 5 1976
感情败类
感情败类 2021-01-24 05:16

This is my string value:

string str = \"32 ab d32\";

And this list is my allowed characters:

var allowedCharacters = new List&l         


        
5条回答
  •  [愿得一人]
    2021-01-24 05:56

    Without regex:

    IEnumerable allowed = srVariable
        .Select(c => lstAllowedCharacters.Contains(c.ToString()) ? c : ' ');
    string result = new string(allowed.ToArray());
    

提交回复
热议问题