I'm trying to write a piece of code right now using .NET 4 that takes the value of an XML node that contains someone's full name. We'll use "John Doe" as an example. I am then writing it into a new XML file with nodes "firstname" and "lastname". Therefore, I need to pull only part of the original XML node innertext at a given time. My current code is this:
Basically I want to somehow iterate through the indexof until it hits the space between the first name and last name and then I want it to take it and set it equal to the firstName string. How can I finish my for statement to accomplish this? Thanks.Code:XmlNode Contacts = Address.SelectSingleNode("Contacts"); XmlNode Contact = Contacts.SelectSingleNode("Contact"); XmlNode Name = Contact.SelectSingleNode("Name"); String nameString = Name.Value.ToString(); String firstName; for (int i = 0; i < nameString.IndexOf(" "); i++) { } XmlElement firstname = shipmentXMLDoc.CreateElement("first-name"); firstname.InnerText = firstName; customer.AppendChild(firstname);




Reply With Quote