Quantcast
Viewing all articles
Browse latest Browse all 224

Parsing ASCII-Only string

Yess, I am still struggling with RegEx.

What I have done so far is to validate a string whether it consists of printable ASCII chars only.

///<summary>/// The name of the host which has originated the Syslog message///</summary>string host;///<summary>/// Gets or sets the name of the host which has originated the Syslog message///</summary>publicstring Host
        {get { return host; }set
            {
                Regex regex = new Regex(@"(\40-\176)");//Printable ASCII characters only                Match match = regex.Match(value);if (match.Groups.Count == 1)
                {
                    host = match.Groups[1].Value;
                }
            }
        }

Is there a shorter way of approaching this?
Also, the RegEx currently produces no match if there is an invalid ASCII char in the string, what would I need to do to just remove the faulty part?
Clean-up crew needed, grammar spill... - Nagy Vilmos

Viewing all articles
Browse latest Browse all 224

Trending Articles