obito1406 obito1406 - 1 year ago 142
C# Question

How to check if a string contains special characters?

I'm using an API, I pass 2 string as parameters.
If I introduce the strings programmatically as:

string a = "Madrid, Spain";

Eveything is fine, the API response is OK.
But everything changes when I use a textbox to introduce the same "Madrid, Spain".

string b = TextBox1.Text;

If I use string b to call the API I get a Request_Denied.

Essentially string a and string b has the same content but something must be different.

C# strings are not null terminated, I've tried to check using
if it ends with a newline since I was using enter to insert the value. I've tried get the char[] representation of the string to see if I was able to get special characters but seems to have none.

Since string in C# is Unicode and some methods use ASCII like Trim(char[]) I'm not sure how to use them.

My main goal is to be able to see all the characters that are contained in the string as ASCII or Unicode, so I can check what is causing the problem with the API.

Edit: In the end it seems like the problem was with the API but I managed to get the hex value as I asked so I learned something new. Thanks

Answer Source

To see the hex value of your characters.

foreach (char c in "Hello World !")
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download