例如,我的正则表达式找到了字符串:some\file\path.xml
我希望它被更改为new_root\some\file\path.xml
.有没有办法使用正则表达式替换方法?如果没有,那么首选方法是什么?
您似乎可以使用Regex.Replace执行您所要求的操作.查看MSDN上正则表达式中的替换文章.
例:
var path = @"C:\some\file\path.xml";
var result = Regex.Replace(path, @"(C:\\)(.*)", "$1new_root\\$2");
Run Code Online (Sandbox Code Playgroud)
结果是C:\new_root\some\file\path.xml.
归档时间: |
|
查看次数: |
179 次 |
最近记录: |