Im trying to split a string into sub parts to pass into a linq database, but ive come up with a problem. The file is a .csv file so its split up by commas example :
1,Ms,Aleshia,Tomkiewicz,14 Taylor St,St. Stephens Ward,Kent,CT2 7PP,01835-703597,[email protected].
However some of the data contains commas in the data field like a county/address is split up with a comma however i dont want it to split i want it to keep that data all together for example address: London,Wimbledon.
im using this code currently to do the chopping:
public static List<string> ReturnCSVFromWeb(string url)
{
System.Net.WebClient client = new WebClient();
string CSVContent = client.DownloadString(url);
List<string> splitted = new List<string>();
string csvFile = CSVContent;
string[] tempStr;
tempStr = csvFile.Split(',','\n');
foreach (string item in tempStr)
{
if (!string.IsNullOrWhiteSpace(item))
{
splitted.Add(item);
}
}
return splitted;
}
London,Wimbledonshould not be separated. You should be thinking of how to properly encode your data in the first place.CSVbecause clearly that's not the format that you have as input. rather specify that you have some custom format that somebody invented and make sure that you define very precisely this format before trying to parse it.