private _WordAndP ProcessWordText(string text) { _WordAndP result = new _WordAndP(); Regex regex = new Regex("[A-Z, a-z, 0-9,']"); if (regex.Match(text).Success == false) { result.IsTranscript = false; result.Left = ""; result.Right = ""; result.Word = text; } else { result.IsTranscript = true; string before = ""; string after = ""; string word = ""; foreach (var c in text.ToCharArray()) { var contains = PunctuationArray.Contains(c); if (word.Length < 1) { if (contains) { before += c.ToString(); } else { word += c.ToString(); } } else { if (contains == true) { after += c.ToString(); } else { word += after + c.ToString(); after = ""; } } } result.Left = before; result.Right = after; result.Word = word; } return(result); }
public void Initialize(string sentenceText) { this.Inlines.Clear(); char[] chars = new char[] { ' ' }; var formated = HttpUtility.HtmlDecode(sentenceText.Trim()); var array = formated.Split(chars, StringSplitOptions.RemoveEmptyEntries); foreach (var text in array) { if (this.Inlines.Count > 0) { this.Inlines.Add(new Run(" ")); } _WordAndP wap = ProcessWordText(text); var wordLength = text.Length - wap.Left.Length - wap.Right.Length; if (wordLength > 0 && wap.IsTranscript == true) { if (wap.Left.Length > 0) { foreach (var item in wap.Left.ToCharArray()) { this.Inlines.Add(new Run(item.ToString())); } } this.Inlines.Add(new SyncableWord(wap.Word)); if (wap.Right.Length > 0) { foreach (var item in wap.Right.ToCharArray()) { this.Inlines.Add(new Run(item.ToString())); } } } else { this.Inlines.Add(new Run(text)); } } }