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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tvnaidu
    Contributor
    • Oct 2009
    • 365

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

    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 SetComputerName Ex 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.

    Code:
    MessageBox.Box(" Received Host Name " + str);
    
    SetComputerNameEx(GCInfo.COMPUTER_NAME_FORMAT.ComputerNamePhysicalNetBIOS, str));
    
    SetComputerNameEx(GCInfo.COMPUTER_NAME_FORMAT.ComputerNamePhysicalDnsHostname, str))
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You can use a regular expression to see if it matches any control characters and if it does, show an error message.

    Comment

    • tvnaidu
      Contributor
      • Oct 2009
      • 365

      #3
      Thanks for the hint, I got it.

      Comment

      Working...