How to split string to dictionary using multiple separators as a key

Viewed 437

I have string that looks like this:

var givenString = "Id: some id Title: sometitle Descritpion: some description Criteria: some criteria <br>more criteria"

How can i split it into dictionary where separator is key and value is from given string. Also there is possibility that one of the separators is not in the text.

I know how to split it into sentence but don't know how to handle situation when one of the separators is missing and how to split it to dictionary.

string[] separators = { "Id:", "Title:", "Descritpion", "Criteria:" }; 
string[] words = givenString.Split(separators, StringSplitOptions.None);

EDIT1: Sample with missing separator:

var givenString = "Id: some id Title: sometitle Criteria: some criteria <br>more criteria"

EDIT2 I forget that some separators can be two words :(. If it make easier I can ask to change separators to be written by uppercase letter:

var givenString = "ID: some id TITLE: sometitle CRITERIA: some criteria <br>more criteria, DIFFERENT CRITERIA: some criteria <br>more criteria"
1 Answers
Related