I have a list of strings:
List<string> list = new <string>
{
"AAB AOC 321"
"AABAOC-WEB_A"
"AABAOC-WEB_B"
}
Now I want to extract from the list of strings largest common prefix, which would ignore the white spaces (and special characters like "_" etc.) and give the below result:
"AABAOC"
I have tried the below method to achieve the same:
var samples = new[] {
"AAB AOC 321"
"AABAOC-WEB_A"
"AABAOC-WEB_B" };
var commonPrefix = new string(samples.First().Substring(0, samples.Min(s => s.Length))
.TakeWhile((c, i) => samples.All(s => s[i] == c)).ToArray());
But the above method wont ignore white spaces and special characters and give the result "AAB", I have tried to play with the TakeWhile functionality but somehow not able to get what I want.