C# string.replace to remove illegal characters -


this question has answer here:

i'm working on program reads files , saves pieces of them according column's title. of titles have illegal characters file names, i've written piece of code handle issues.

string headerfile = savedir + "\\" + tvs.nodes[r].text.replace("\"", "").replace               ("/","").replace(":"," -").replace(">","(greater than)") + ".csv"; 

is there nicer way of doing don't have 4 .replace()? or there sort of built in illegal character remover don't know of?

thanks!

edit: not need replace characters specific. blank space sufficient.

regular expressions way that, not when you're replacing every character different. might consider replacing them same thing, , using system.io.path.getinvalidfilenamechars().

string filename = tvs.nodes[r].text;  foreach(char c in system.io.path.getinvalidfilenamechars()) {     filename = filename.replace(c, '_'); } 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -