By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
458,140 Members | 1,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 458,140 IT Pros & Developers. It's quick & easy.

How to detect Control characters inside before I set HostName on my computer (C#)

P: 365
I am looking for some help on how to detect "Control Characters" once I receive HostName inside program, I am getting string, I am using SetComputerNameEx to set HostName, buit some times if any Control Characters present, I need to send error back. Here "str" carried string (HostName), sometimes it might contain Control characters (/\\|<>+=;,?), I need to detect and send error, how can I detect.

Expand|Select|Wrap|Line Numbers
  2. MessageBox.Box(" Received Host Name " + str);
  4. SetComputerNameEx(GCInfo.COMPUTER_NAME_FORMAT.ComputerNamePhysicalNetBIOS, str));
  6. SetComputerNameEx(GCInfo.COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, str))
Dec 30 '12 #1
Share this Question
Share on Google+
2 Replies

Expert Mod 10K+
P: 12,427
You can use a regular expression to see if it matches any control characters and if it does, show an error message.
Dec 30 '12 #2

P: 365
Thanks for the hint, I got it.
Dec 30 '12 #3

Post your reply

Sign in to post your reply or Sign up for a free account.