2

How to add the three dots at a position in the text and prevent these three dots from truncating any word or being placed after puntuation marks (.,;:)?

This is my javascript function

let parseText = function(text, limit){
    return text.substring(0, limit) + '...';
};
David Ortiz
  • 997
  • 1
  • 14
  • 22
Pada Dapa
  • 33
  • 1
  • 7

1 Answers1

2

My answer to this post will help you:

For preventing the dots in the middle of a word or after a punctuation symbol.

let parseText = function(text, limit){
if (text.length > limit)
    for (let i = limit; i > 0; i--){
        if(text.charAt(i) === ' ' && (text.charAt(i-1) != ','||text.charAt(i-1) != '.'||text.charAt(i-1) != ';')) {
            return text.substring(0, i) + '...';
        }
    }
else
    return text;
};
Community
  • 1
  • 1
David Ortiz
  • 997
  • 1
  • 14
  • 22