+ 1
Once upon a time there was a set, how to find a element of a set
I would like to do something like if character in ('E', '^', ',','.') //capital E, a dakje, a comma and a dot { //do something } I thought there was a set, or a enum and also a "in" - keyword. But I can't find it anymore. What is the correct way to find a member of a set
6 Antworten
+ 5
You could convert the string to a char array and then use the Contains function.
to Contains: https://stackoverflow.com/questions/13257458/check-if-a-value-is-in-an-array-c
to char array: https://msdn.microsoft.com/en-us/library/2c7h58e5(v=vs.110).aspx
finally for more complex constructs like "keyword" in "ksadkeywordsads" you can always use RegEx
0
Oeps. Then I have a memory flash back from when I was programming in Delphi (Pascal). Which still is a good language.
Do you know how to do it in C# ? ;-)
0
Dont worry, we are not talking about get; set;
We are talking about a group of variables.
0
I want to analyze a string for certain characters like
E capital E
^ dakje ( I do not the english word)
, comma
. dot
If they are in the string, I want to do something
0
@ace : yes that is what I want to do.
0
Thank you all.
I used the array and contains method. From the stackoverflow link from Chrizzhigh.
No it works.
static bool IsAString(string userInput)
{
bool result = true;
char[] ExceptionArray = new char[] {'E', '^', '.', ','};
foreach (char ch in userInput)
{
if (ExceptionArray.Contains(ch))
{
return false;
}
}
return true;
}