Event Full Details
hareimprove this question edited Mar 6 '15 at 15:25
trejder
7,6011674148
asked Jul 1 '10 at 21:28
Alex
16.3k110334520
5
might be better to use the ellipsis character … – Keet Apr 14 '13 at 22:03
1
check out my answer if you need to avoid words cutting. – TechNyquist Feb 3 '14 at 9:21
theunixshell.blogspot.in/2012/12/… – Vijay Apr 17 '14 at 14:13
Try This Link, May help You... stackoverflow.com/a/26098951/3944217 – edCoder Sep 29 '14 at 11:46
add a comment
18 Answers
active oldest votes
up vote
425
down vote
accepted
//The simple version for 10 Characters from the beginning of the string
string = substr(string,0,10).'...';
Update:
Based on suggestion for checking length (and also ensuring similar lengths on trimmed and untrimmed strings):
string = (strlen(string) > 13) ? substr(string,0,10).'...' : string;
So you will get a string of max 13 characters; either 13 (or less) normal characters or 10 characters followed by '...'
