private void UpdateListOfSections(string splitText, TweetSectionType sectionType, List <TweetSection> listOfSections) { switch (sectionType) { case TweetSectionType.HashTag: splitText = "#" + splitText; break; case TweetSectionType.UserMention: splitText = "@" + splitText; break; default: throw new ArgumentException("Invalid section type specified. Must be a HashTag or UserMention"); } for (var i = 0; i < listOfSections.Count; i++) { var tweetSection = listOfSections[i]; if (tweetSection.Type != TweetSectionType.Text) { continue; } //var split = tweetSection.Text.Split(new[] { splitText }, StringSplitOptions.RemoveEmptyEntries); var split = Regex.Split(tweetSection.Text, splitText, RegexOptions.IgnoreCase); listOfSections.RemoveAt(i); for (var j = 0; j < split.Length; j++) { if (j != 0) { listOfSections.Insert(i++, new TweetSection(splitText, sectionType)); } listOfSections.Insert(i++, new TweetSection(split[j], TweetSectionType.Text)); } } }
public TweetSection(string text, TweetSectionType type) { Text = text; Type = type; }