Skip to main content

Posts

Showing posts with the label #Split and Preserve Word in c#

C# Split the string and preserve the word.

using System.Text.RegularExpressions;        private List<string> SplitPreserveWord(string sentence, int splitLength = 132)         {             string[] words = sentence.Split(' ');             var parts = new List<string>();             string part = string.Empty;             foreach (var word in words)             {                 if (part.Length + GetSpecialCharCount(part) + word.Length + GetSpecialCharCount(word) < splitLength)                 {                     part += string.IsNullOrEmpty(part) ? word : " " + word;                 }                 el...