这是我的问题
我有以下数组(例如)
string[] arr = new[] { "s_0001", "s_0002", "s_0003", "sa_0004", "sa_0005", "sab_0006", "sab_0007" };
我想做一些给出以下输出的事情
s_0001
sa_0004
sab_0006
我已经尝试了一切,但没有运气!这将是一个长期项目的第一步,任何帮助将不胜感激。
[编辑] 我不知道字母什么时候会改变,但我知道总会有一个下划线来分隔字母和数字。我需要以某种方式提取这些字母,然后去掉重复的
[编辑]更具体地说..我想在下划线之前有每个字符串的唯一条目,我不关心的数字
[编辑] 好的,伙计们!你真的很活跃,我给你。我没想到我会得到这么快的答案。但看起来(因为我在过去 8 小时里一直在研究这个问题)我问错了问题
这是我的代码
//Loop through the XML files in the Directory and get
//the objectName and GUID of each file
string[] arr_xmlFiles = Directory.GetFiles(Dir, "*.xml"); //Array with all XML Files in the Directory
foreach (string xmlFile in arr_xmlFiles)
{
try
{
//Get the XMLs Name
XDocument xmlF = XDocument.Load(xmlFile);
string objectName = xmlF.Root.Name.ToString();
//Get the XMLs GUID
XElement oDcElement = xmlF.Root.FirstNode as XElement;
Guid oGuid = new Guid(oDcElement.Attribute("DataclassId").Value);
//Prints out the results
Console.WriteLine(" " + objectName + " " + oGuid);
}
catch (XmlException) { }
}
我所做的基本上是以下我在一个目录中获取所有 XML 文件(它们包含 ObjectName 及其 GUID)
IE
CM_Commands [0ee2ab91-4971-4fd3-9752-cf47c8ba4a01].xml
CM_Commands [1f627f72-ca7b-4b07-8f93-c5750612c209].xml
抱歉,破坏符号是“[”而不是“_”,但这没关系。
现在我将所有这些 XML 保存在一个数组中,然后我想从这些 XML 中提取每个 XML 的 ObjectName 和 GUID
在我这样做之后,我只想对每个拥有相同 objectName 的 XML 之一进行一些修改
就这样