我要转换的配置如下所示:<sdfsdfsd><blah><mypath>D:\my\old\path\aaa</mypath></blah><blah><mypath>D:\my\old\path\bbb</mypath></blah><blah><mypath>D:\my\old\path\ccc</mypath></blah></sdfsdfsd>我要做的就是用D:\my\old\path\<unique value>替换D:\my\new\path\<unique value>我只看到示例替换了 之间或中的属性的完整值。我只想做一个简单的字符串替换文件中的所有位置,这可能吗? 最佳答案 试试xml linqusing System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Xml;using System.Xml.Linq;namespace ConsoleApplication1{ class Program { static void Main(string[] args) { string xml = "<sdfsdfsd>" + "<blah>" + "<mypath>D:\\my\\old\\path\\aaa</mypath>" + "</blah>" + "<blah>" + "<mypath>D:\\my\\old\\path\\bbb</mypath>" + "</blah>" + "<blah>" + "<mypath>D:\\my\\old\\path\\ccc</mypath>" + "</blah>" + "</sdfsdfsd>"; XElement element = XElement.Parse(xml); foreach(XElement mypath in element.Descendants("mypath")) { mypath.SetValue(((string)mypath).Replace("old","new")); } } }}关于c# - 如何用XDT转换替换字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44528595/
10-16 04:50