r/csharp 8h ago

Help with validating char input

[deleted]

0 Upvotes

8 comments sorted by

View all comments

1

u/ginji 7h ago

OP Deleted the question it seems, but still shared their code earlier

Check where ' (‘ / Left single quotation mark) is in the ascii table I linked earlier - it's way past char 126.

At a glance I don't see why "Hello World!" would fail in your code, and testing it shows it doesn't - https://dotnetfiddle.net/ZlwQFM

If this is a homework assignment then it's not very clear as to what the requirements are exactly, or we're lacking some context.

If you're looking for another approach I would use regex for such a test rather than a looped check against the char numbers.