Naveen Pittala
Member
Hello Team,
I am having a requirement to split string of (Key, Value) format. First value will be field name and second value will be its value. Input string may vary with different length.
Example :
Input String : 'Name|Naveen|Job|Software|Country|India'.
Expected Output : Name = Naveen
Job = Software
Country = India
values to be in separate data item or in collection.
I wrote custom code to achieve this requirement, but it is throwing an error. Please find attached screenshot for error.
My Code :
char[] delimiterChar = {'|'};
string input = "Name|Naveen|Job|Software|Country|India";
Dictionary<string,string> output= VisitorDetail(input.Trim('|'));
Dictionary<string,string> VisitorDetail(string input)
{
Dictionary<string, string> result = new Dictionary<string, string>();
string[] keyValues = input.Split(delimiterChar);
for (int i = 0; i < keyValues.Length; i = i+2)
{
result.Add(keyValues, keyValues[i + 1]);
}
return result;
}
'result' am storing in collection.
Is there any other way to achieve this requirement?
Thanks.
I am having a requirement to split string of (Key, Value) format. First value will be field name and second value will be its value. Input string may vary with different length.
Example :
Input String : 'Name|Naveen|Job|Software|Country|India'.
Expected Output : Name = Naveen
Job = Software
Country = India
values to be in separate data item or in collection.
I wrote custom code to achieve this requirement, but it is throwing an error. Please find attached screenshot for error.
My Code :
char[] delimiterChar = {'|'};
string input = "Name|Naveen|Job|Software|Country|India";
Dictionary<string,string> output= VisitorDetail(input.Trim('|'));
Dictionary<string,string> VisitorDetail(string input)
{
Dictionary<string, string> result = new Dictionary<string, string>();
string[] keyValues = input.Split(delimiterChar);
for (int i = 0; i < keyValues.Length; i = i+2)
{
result.Add(keyValues, keyValues[i + 1]);
}
return result;
}
'result' am storing in collection.
Is there any other way to achieve this requirement?
Thanks.