I have a string as below
string error_message= "{\"2705\":\"Error importing username: 3167763, primary email: [email protected], error: User already exists but Email does not match: [email protected] vs [email protected]\",\"10001\":\"Error importing username: 3195330, primary email: [email protected], error: User already exists but Email does not match: [email protected] vs [email protected]\"}";
from the above string i need to find the repeating text "Error importing username:" and take the username value next to it along with corresponding email id after the text "primary email:" and store it in in datatable with expected output as below
Expected Result in Datatable as below
username primary email
3167763 [email protected]
3195330 [email protected]
below is the code sample i have where i can able to get all the username in list i need to modify the below code to get both username and corresponding primary email id as well in a collection your help will be very much useful
List<int> list = Regex.Matches(error_message, @"(?<=Error importing username: )\d+")
.Cast<Match>()
.Select(match => int.Parse(match.Value))
.ToList();