How can I filter out the specific characters from an inputted string?
Please see below for how I have tried.
using System;
namespace PlainTest
{
class arrayTest
{
static void Main(string[] args)
{
bool doAlways = true;
int i = 1;
do
{
Console.WriteLine("Test Number : {0}", i++);
Console.Write("Key in the string: ");
char[] alpha = { 'a', 'b', 'c' };
string text = Console.ReadLine();
string filterAlphabet = text.Trim(alpha);
Console.WriteLine("The input is : {0}", text);
Console.WriteLine("After trimmed the alpha a,b,c : {0}", filterAlphabet);
} while (doAlways == true);
}
}
}
But when I tried with the character to be trimmed in between the numbers, the filter didn't work. Please see below for outputs for different inputs.
Test Number : 1
Key in the string: 123abc
The input is : 123abc
After trimmed the alpha a,b,c : 123
Test Number : 2
Key in the string: abc123
The input is : abc123
After trimmed the alpha a,b,c : 123
**Test Number : 3
Key in the string: aa1bb2cc3
The input is : aa1bb2cc3
After trimmed the alpha a,b,c : 1bb2cc3**
Test Number : 4
Key in the string: aaabbbccc123
The input is : aaabbbccc123
After trimmed the alpha a,b,c : 123
Test Number : 5
Key in the string: a12bc
The input is : a12bc
After trimmed the alpha a,b,c : 12
Test Number : 6
Key in the string: