0

I am reading in a CSV file to convert to XML format. How do I concatenate a fixed string before one of the fields.

In this example i need to attach "domain\" to the username

string[] csvString = File.ReadAllLines("file.csv");

        XElement xmlString = 
            new XElement("XML",
                new XElement("IDENTITIES",
                from str in csvString
                let fields = str.Split(',')
                select  new XElement("IDENTITY", 
                            new XAttribute("ID", fields[1]),
                            new XAttribute("SERVICE", "SERV"),
                            new XAttribute("DOMAIN_USER",  fields[2]),
                            new XAttribute("PASSWORD","PASSWORD")

How would I set DOMAIN_USER XAttribute to a concatenated "DOMAIN\" & fields[2]?

1 Answers1

0

Why don't you simply concatenate strings ?

new XAttribute("DOMAIN_USER",  "DOMAIN\\" + fields[2]),
Selman Genç
  • 100,147
  • 13
  • 119
  • 184
  • 1
    This was actually the first thing I tried, only, I used a single "\" and kept getting a Newline in constant error so I figured I wasn't concatenating string correctly. Considering this is my first attempt at a C# application, I had no idea you needed to use "\\". – Th3GreatMonk Feb 10 '14 at 13:49