Share Blog

Wednesday, June 20, 2018

How to extract data from string in C#

I getting data in my application through Code. Code returns data in several parameters/variables. One of the parameter return below string.



string input = @"Some text BLA/123/5345/349230498 some more text PNR: 12345678, Name: John, CallName: Peter, TimeStamp: 01.10.2015";
string value = String.Empty;

List<string> keyValuePairs = input.Split(',').ToList();

foreach (var keyValuePair in keyValuePairs)
{
string key = keyValuePair.Split(':')[0].Trim();
if (key == "Name")
{
value = keyValuePair.Split(':')[1];
}
}

No comments:

Post a Comment