I am trying to replace several characters in some line 14/04/2010 17:12:11and get, for example, the following result:
14/04/2010 17:12:11
14%04%2010%17%12%11
I know about the method Replace, but its definition looks like Replace(Char,Char). This means using 3 times in a chain of methods. Doesn't look idiomatic. How to solve the problem in the best way? Ordinary expressions? Any ways to avoid them?
Replace
Replace(Char,Char)
Chain:
string s1 = "14/04/2010 17:12:1"; string s2 = s1.Replace("/","%").Replace(" ","%").Replace(":","%");
Regex.Replace(myString, "[/ :]", "%");
Simple but elegant!
Regex, . :
Regex
string date2 = Regex.Replace(date1, @"\D", "%");
, :
static string Replace(string s, string c, char n) { for (int i = 0; i < c.Length; i++) s = s.Replace(c[i], n); return s; }
.
string s1 = "14/04/2010 17:12:11"; string s2 = Replace(s1, "/ :", '%'));
Source: https://habr.com/ru/post/1742174/More articles:R using rpart with 4000 entries and 13 attributes - rShould a JMS application create a new session for each message it sends? - javaПереход к определенной позиции в ListView при создании. (Android) - androidHow do I get Hudson to stop slipping parts of my shell script? - hudsonПлюсы и минусы, использующие Mercurial over Subversion - version-controlC # /. NET Project - Am I setting things right? - referencea simple modification leads to an error - javaSerializing WCF with Messages - enumsHow to make this jQuery snippet work in Internet Explorer? - jqueryPHP variable passed to JasperReports server for reports - jasper-reportsAll Articles