akr*_*nov 3 .net c# string replace
我尝试在一些字符串中替换几个字符 14/04/2010 17:12:11,例如,得到下一个结果:
14%04%2010%17%12%11
Run Code Online (Sandbox Code Playgroud)
我知道方法Replace,但它的定义看起来像Replace(Char,Char).这意味着在方法链中使用它3次.看起来不那么惯用.如何以最佳方式解决问题?常用表达?有什么方法逃脱它们?
Regex.Replace(myString, "[/ :]", "%");
Run Code Online (Sandbox Code Playgroud)
简单而优雅!
链它:
string s1 = "14/04/2010 17:12:1";
string s2 = s1.Replace("/","%").Replace(" ","%").Replace(":","%");
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1703 次 |
| 最近记录: |