C#: check if a string start with any character in a list
Posted
by
JoesyXHN
on Stack Overflow
See other posts from Stack Overflow
or by JoesyXHN
Published on 2011-01-12T22:42:40Z
Indexed on
2011/01/12
22:53 UTC
Read the original article
Hit count: 142
c#
Hi,
I want to check whether a string starts with any character in a list. My current implementation in C# is as follows:
char[] columnChars = new char[] { 'A', 'B', 'C', 'D', 'E' };
private bool startWithColumn(string toCheck)
{
for(int i=0; i<columnChars.Length; i++)
if (toCheck.StartsWith(columnChars[i]+""))
{
return true;
}
return false;
}
I would like to know if any solution is better?
© Stack Overflow or respective owner