I'm trying to detect if a string contains any characters outside of a range of values (ASCII), from ,(comma) to |(pipe). I tried this and it didnt work
string.Contains("[^,-|]");
any ideas?
I'm trying to detect if a string contains any characters outside of a range of values (ASCII), from ,(comma) to |(pipe). I tried this and it didnt work
string.Contains("[^,-|]");
any ideas?
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Guest UserRank #1,422 · 1.2K reputationPosted Jan 14, 2008, 10:30 AM EST
IndexOfAny() should work, but since it takes a char array instead of a string, you'll need to do an extra function call, like this:
string textToEvaluate = "ABCDEF[GHIJ";
string badChars = "[^,-|]";
int i = textToEvaluate.IndexOfAny(badChars.ToCharArray());
If none of the bad chars are in the string to be evaluated, i = -1, otherwise it will contain the position of the first bad char.
HTH
rocket25 reputationPosted Jan 14, 2008, 10:50 AM EST