[Solved] How Can I Parse CSV in C# [closed]


Here’s the simplest way to do it that I know of…

        var txt = "-123.118069008,49.2761419674,0 -123.116802056,49.2752350159,0 -123.115385004,49.2743520328,0";
        var output = new StringBuilder();
        foreach (var group in txt.Split(' '))
        {
            var parts = group.Split(',');
            var lat = double.Parse(parts[0]);
            var lng = double.Parse(parts[1]);
            if (output.Length > 0)
                output.AppendLine(",");
            output.Append("new google.maps.LatLng("+lat+","+lng+")");
        }
        MessageBox.Show("["+output+"]");

The result is…

[new google.maps.LatLng(-123.118069008,49.2761419674),

new google.maps.LatLng(-123.116802056,49.2752350159),

new google.maps.LatLng(-123.115385004,49.2743520328)]

1

solved How Can I Parse CSV in C# [closed]