akrisanov akrisanov - 3 years ago 99
C# Question

Replacing few different characters in a string

I try to replace few characters in some string

14/04/2010 17:12:11
and get, for example, next result:


I know about method
, but its definition looks like
. Which means using it 3 times in method chain. Doesn't look idiomatic. How to solve the problem in an optimal way? Regular expressions? Any ways to escape them?

Answer Source

Chain it:

string s1 = "14/04/2010 17:12:1";

string s2 = s1.Replace("/","%").Replace(" ","%").Replace(":","%");
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download