Does the length of words1 always equal the length of words2?
If so you could try below code:
List<string> RESULTVALUE = new List<string>();
string str1 = "Sub1#Sub2";
string[] words1 = str1.Split('#');
string str2 = "400,500";
string[] words2 = str2.Split(',');
double value = 0;
for (int i = 0; i < words1.Length; i++)
{
value = Convert.ToDouble(words2[i]);
RESULTVALUE.Add(words1[i] + "=" + value);
}
Best Regards,
Billy
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
If I am not wrong then what I understood is, you want to parse two lists and want to concatenate into one with pairing values from both the list. To achieve this you can you Dictionary as below. Also assuming length of both of the lists will be same. Or
you need to apply extra validation.
Member
209 Points
701 Posts
LIST - How to form a list in the given example
Jul 21, 2017 07:05 AM|gani7787|LINK
Hi,
I want to form below output after executing my code.
Output should come as mentioned below format as list <string> RESULTVALUE .
list <string> RESULTVALUE
[0]Sub1 = 400
[1]Sub2 = 500
i'm struggling to form the loop
below is my code
List<string> RESULTVALUE = new List<string>();
string str1 = "Sub1#Sub2";
string[] words1 = str1.Split('#');
string str2 = "400,500";
string[] words2 = str2.Split(',');
double value = 0;
for (int i = 0; i < words1.Length; i++)
{
for (int j = 0; j < words2.Length; i++)
{
value = Convert.ToDouble(words2[j]); ????????
}
RESULTVALUE.Add(words1[i] + "=" + value); ????????
}
Final output is :
list <string> RESULTVALUE
[0]Sub1 = 400
[1]Sub2 = 500
where we need to change the code..?
Contributor
2260 Points
815 Posts
Re: LIST - How to form a list in the given example
Jul 21, 2017 09:29 AM|Billy Liu|LINK
Hi gani7787,
Does the length of words1 always equal the length of words2?
If so you could try below code:
Best Regards,
Billy
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
20 Points
24 Posts
Re: LIST - How to form a list in the given example
Aug 03, 2017 11:22 AM|rahulmarathe|LINK
Hi
gani7787,
If I am not wrong then what I understood is, you want to parse two lists and want to concatenate into one with pairing values from both the list. To achieve this you can you Dictionary as below. Also assuming length of both of the lists will be same. Or you need to apply extra validation.
Output:
Sub1, 400
Sub2, 500
Participant
1600 Points
912 Posts
Re: LIST - How to form a list in the given example
Aug 04, 2017 06:42 AM|PaulTheSmith|LINK
Or with a bit less code ....