My goal is to store the strings I got from my foreach loop into different variables.
For example, I have the string Apple=3;Orange=10;Mango=12
, I need to store Apple
, Orange
, and Mango
to string sFruit1
, sFruit2
, sFruit3
(these strings need to increment also depending on how many items are there in the string like if 4, I need to have a sFruit4 variable also) after doing a foreach loop. This seems to be easy but I cannot get the right solution. Here is my code:
string sRes = "Apple=3;Orange=10;Mango=12";
string[] sSplitStrings = sRes.Split(';');
foreach (string sFruit in sSplitStrings)
{
string sLabel = sFruit.Substring(0, sFruit.IndexOf("="));
}