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 &quot;[^&quot;a-za-z0-9_?&lt;&gt;+=./:- ]&quot; - [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

Popular posts from this blog

google api - Incomplete response from Gmail API threads.list -

Installing Android SQLite Asset Helper -

Qt Creator - Searching files with Locator including folder -