Hey all, here is my problem
I have the following array (for example)
string[] arr = new[] { "s_0001", "s_0002", "s_0003", "sa_0004", "sa_0005", "sab_0006", "sab_0007" };
I want to do something that gives the following output
s_0001
sa_0004
sab_0006
I've tried everything but no luck! this will be the first step in a long project and any help would be most appreciated.
[edit] I don't know when will the letters change, but I know that there will always be an underscore to separate the letters from the numbers. I need to somehow extract these letters, and then get rid of the duplicate ones
[edit] More specifically.. I wanna have unique entries of each string before the underscore, the numbers I don't care about
[edit] Ok guys! You're really active I give you that. I didn't expect I would get such quick answers. But as it seems (since I've been working on this for the last 8 hours) I've asked the wrong question
Here is my code
//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) { }
}
What I'm doing basically is the following I get all the XML files in a directory (They contain the ObjectName with its GUID)
i.e
CM_Commands [0ee2ab91-4971-4fd3-9752-cf47c8ba4a01].xml
CM_Commands [1f627f72-ca7b-4b07-8f93-c5750612c209].xml
Sorry the breaking sign was '[' not '_' but it doesn't matter.
Now I save all these XMLs in an Array, then I wanna extract from these XMLs the ObjectName and the GUID for each one
After I do that I wanna do some modifications on only one of each XML that holds the same objectName
That's all