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

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

100+
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
  1.  
  2. MessageBox.Box(" Received Host Name " + str);
  3.  
  4. SetComputerNameEx(GCInfo.COMPUTER_NAME_FORMAT.ComputerNamePhysicalNetBIOS, str));
  5.  
  6. SetComputerNameEx(GCInfo.COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, str))
  7.  
  8.  
  9.  
Dec 30 '12 #1
Share this Question
Share on Google+
2 Replies


Rabbit
Expert Mod 10K+
P: 12,359
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

100+
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.