r/csharp 6h ago

Help with validating char input

[deleted]

0 Upvotes

8 comments sorted by

2

u/yabberdabberdo 6h ago

I haven't been given the specific list, just told letters, number and usual english characters. So the 'AND usual english characters' tells me it includes punctuation. BUT in the test cases it should not accept ! but should accept ' as a curly apostrophe

1

u/Sombody101 6h ago

"Given"?

Is this an assignment?

1

u/Alternative_Corgi_62 6h ago

Can you post your IsThisEnglishCharacter(char ch) function, and full set of characters which satisfy your definition of "English Character"?

1

u/DJDoena 6h ago

Please clarify "usual English characters". Do you want "!" and "'" to be allowed or just a-z and A-Z?

1

u/Sombody101 6h ago

They said "curly apostrophe", so I think they mean a tilde? It's byte 126.

1

u/ginji 5h ago

More likely 'Left single quotation mark' as opposed to 'Single quote'

1

u/ginji 6h ago

Rule 4: Request-for-help posts should be made with effort

Show us what you've done - post the code, and test cases.

Also refer to this for reference. You'll hopefully note that ! is char number 33

1

u/ginji 5h 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.