-1

I am having string which gives data more like to csv format .

&stamp;field1;field2;field3;field4;&event 
10:44:00.6100;0.000;0.000;0.000;0.000; 10:44:00.7100;23.2;0.230;411.2;0.000; 10:44:00.8100;0.000;0.000;1.022;0.000;      10:44:00.9100;8.000;0.000;232.3;0.000;
 10:44:01.2100;0.000;0.000;0.000;0.000; 10:44:01.3100;23.2;0.230;411.2;0.000; 10:44:01.5100;0.000;0.000;1.022;0.000; 10:44:01.7100;8.000;0.000;232.3;0.000;

I want to deserialize this data.

Nimantha
  • 6,405
  • 6
  • 28
  • 69
user1260967
  • 89
  • 1
  • 2
  • 14
  • What is the contents here? And what do you want to do with the data? Are you sure you do not just want to open this in Excel or some similar application? – Kjartan Apr 23 '13 at 15:18
  • If the data is just like CSV except for using semicolons instead of commas, then use a CSV parser that allows you to customize the delimiter. If it's a simpler format, where you can just split on the semicolons, then do that. Either way, see duplicate. – Peter Duniho Apr 06 '21 at 03:31

2 Answers2

0

this will give you a list of strings "split" at every ; char. you will want to trim and parse the values after. hope this helps

var stringOfData = "0:44:00.6100;0.000;0.000;0.000;0.000;     10:44:00.7100;23.2;0.230;411.2;0.000; 10:44:00.8100;0.000;0.000;1.022;0.000;      10:44:00.9100;8.000;0.000;232.3;0.000;";
List<string> parsed = new List<string>();
parsed.AddRange(stringOfData.Split(';'));
workabyte
  • 3,496
  • 2
  • 27
  • 35
  • Thnxs for suggestion , but any way to deserialize it in some particular format as by using split i have to use loops,arrays to make it in order .... – user1260967 Apr 23 '13 at 14:53
  • can you be more specific to what you mean by "in some particular format?" could you give an example of what you get and what you want to get out of it so i can better answer your question – workabyte Apr 23 '13 at 15:26
0
string line = String.Empty;
string[] parts = null;
using (StreamReader sr = new StreamReader(new FileStream(@"C:\yourfile.csv", 
                                          FileMode.Open)))
{
    while ((line = sr.ReadLine()) != null)
    {
        parts = line.Split(new [] { ';' });
        //Do whatever you want to do with the array of values here
    }
}

As for the deserialization part of the question; you would need to specify the kind of format you would want. If you just want a collection of numbers you want to loop through, you could just add every value to a generic List.

If you want a specific format, you could create a class with fields for each of those values and populate a generic list of that class using those values.

Kjartan
  • 18,591
  • 15
  • 71
  • 96
Mark Mintoff
  • 282
  • 3
  • 5