truncate,substring,text,keeping,preserving,word,without,cutting,complete,words

Kubilay 4/12/2017 0

C# method to truncate a text by keeping words.

C#
  public static String TruncateWithPreservation(String s, int len)
        {
            String[] words = Regex.Split(s, "\\s ");
            String finalResult = "";
            foreach (String word in words)
            {
                String tmp = finalResult   " "   word;
                if (tmp.Length > len)
                {
                    return finalResult   " ...";
                }
                finalResult = tmp;
            }
            return finalResult;
        } 

Report Bug

Please Login to Report Bug

Reported Bugs

Comments

Please Login to Comment

Comments