i have string like this:
string myOrder= " \"orderID\":\"123456\",\"orderName\":\"ABC\",\"orderDate\":\"20170120\""
I am trying to get values of orderID, orderName, orderDate by the following method:
List orderName= ExtractFromString(myOrder, "\"orderName\":\"", "\",");
private static List ExtractFromString(string text, string startString, string endString)
{
List matched = new List();
int indexStart = 0, indexEnd = 0;
bool exit = false;
while (!exit)
{
indexStart = text.IndexOf(startString);
indexEnd = text.IndexOf(endString);
if (indexStart != -1 && indexEnd != -1)
{
matched.Add(text.Substring(indexStart + startString.Length,
indexEnd - indexStart - startString.Length));
text = text.Substring(indexEnd + endString.Length);
}
else
exit = true;
}
return matched;
}
I am getting null exception at matched.add(...
Advance thanks,
Darma
Nitin SontakkeRank #264 · 9.6K reputationPosted Jan 24, 2017, 2:44 AM EST
darma tejaRank #3,199 · 449 reputationPosted Feb 12, 2017, 10:02 PM EST
Dinesh SanthalingamRank #2,085 · 690 reputationPosted Jan 30, 2017, 11:53 PM EST
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questionsTop experts