trim - How to filter out the characters from user inputed string in c#? -


this question has answer here:

how can filter out specific characters inputed string? please see below how have tried.

    using system;      namespace plaintest     {         class arraytest         {             static void main(string[] args)             {                 bool doalways = true;                 int = 1;                                 {                     console.writeline("test number : {0}", i++);                     console.write("key in string: ");                     char[] alpha = { 'a', 'b', 'c' };                     string text = console.readline();                     string filteralphabet = text.trim(alpha);                     console.writeline("the input : {0}", text);                     console.writeline("ater trimed alpha a,b,c : {0}", filteralphabet);                   } while (doalways == true);             }         }     } 

but when tried character trimmed in between numbers. filter doesn't work. please see below outputs different inputs.

test number : 1 key in string: 123abc input : 123abc ater trimed alpha a,b,c : 123  test number : 2 key in string: abc123 input : abc123 ater trimed alpha a,b,c : 123  **test number : 3 key in string: aa1bb2cc3 input : aa1bb2cc3 ater trimed alpha a,b,c : 1bb2cc3**  test number : 4 key in string: aaabbbccc123 input : aaabbbccc123 ater trimed alpha a,b,c : 123  test number : 5 key in string: a12bc input : a12bc ater trimed alpha a,b,c : 12  test number : 6 key in string:  

please advise me. thanks.

instead of using trim, can loop through string characters want remove , replace them empty string:

var alpha = new string[] { "a", "b", "c" }; foreach (var c in alpha) {     text = text.replace(c, string.empty); } 

Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -