c# - How do I allow whitespace with Regex.Replace -
i have created web service method in asp.net c#, , using regex.replace method beacause of invalid characters returning in result, how allow white space in method,because in regex.replace method, white space eliminated. see code:
public string list(long empid, string name, string pwd, long id) { httpwebrequest request = (httpwebrequest)webrequest.create(link); request.connection = regex.replace((empid, name, pwd, id), "[^\"a-za-z0-9_?<>+=./:-]", ""); string connection = request.connection; return connection; }
if use space in regex.replace this:
request.connection = regex.replace((empid, name, pwd, id), "[^\"a-za-z0-9_?<>+=./:- ]", "");
i getting error:
system.argumentexception: parsing "[^"a-za-z0-9_?<>+=./:- ]" - [x-y] range in reverse order.
you can add character class.
[^\"a-za-z0-9_?<>+=./: -]
if use space this:
[^\"a-za-z0-9_?<>+=./:- ]
getting error....
within character class [ ]
can place hyphen first or last character in range. if place hyphen anywhere else need escape it.
Comments
Post a Comment