0

I have an array of strings separated by ; , like this

myArr[0]="string1;string2;string3"
myArr[1]="string4;string5;string6"

how can i convert it into an list of ValueTuple(string,string,string)?

List<(string,string,string)>
L4marr
  • 291
  • 2
  • 16
  • 1
    Well, `string.Split` will convert each of those strings into an array (`string[] strArray`). Then you'll need to create a tuple from the array (`var tuple = (strArray[0], strArray[1], strArray[2]);`. Finally add each tuple into a `List<(string,string,string)>`. Make sure to code defensively, a missing semi-colon will mess your code up nicely. If you are looking for some magic LINQ statement, that's beyond my LINQ-foo, sorry. – Flydog57 Mar 29 '21 at 01:58

1 Answers1

1

You can use Linq like this:

    var myArr= new string[2];
    myArr[0]="string1;string2;string3";
    myArr[1]="string4;string5;string6";
                
    var tuples = myArr.Select(x=> 
    {
       var separated = x.Split(";");
       return (separated[0],separated[1], separated[2]);
    });
                
foreach(var tuple in tuples)
{
Console.WriteLine($"{tuple.Item1}, {tuple.Item2}, {tuple.Item3}");
}
bolkay
  • 1,881
  • 9
  • 20