c# - Regex: spliting first, last name into comma-separated list eg "john smith Jr." to "john", "smith", "Jr." -
i using c# (asp .net) , have text box accepts name entries performs query on db.
i want use in
clause obtain possible values in c# page 1 string
e.g 'john smith' use regex break 'john','smith'
string text1 = "'"+regex.replace(text,@"[^a-za-z0-9\-\.\']+","','")+"'";
however names 'john smith jr.' or 'bruce o'brien', fails (due special characters)
what missing in regex?
thanks
regex not easiest way this. instead, i'd recommend string.split method, works defining whitespace characters between words are:
string fullname = "bruce o'brien"; string[] names; char[] separators = new char [] {' '}; // space character, in case names = fullname.split(separators);
once you've got array of names, it's easy turn csv string if that's need.
Comments
Post a Comment