Version 5 of Ellipsis

Updated 2005-12-23 23:23:18

Richard Suchenwirth 2005-10-04 - "Ellipsis" is Greek for "left out". More specifically,

 it's the name of the character(s) "..." (three ASCII periods, or fancier the Unicode \u2026) 

indicating that something was left out. When a string is truncated to fit into a given length, the following proc adds an ellipsis where necessary:

 proc string'limit {str length} {
   expr {[string length $str]>$length? 
        "[string range $str 0 [incr length -4]]..."
   : $str}
 }
 % string'limit hello 10
 hello
 string'limit "hello long string" 10
 hello l...

escargo 4 Oct 2005 - There are typographic rules for the use of ellipsis that make its use less than straightforward [L1 ].


JH - The string replace command is designed to do the ellipsis without otherwise modifying the string. Just use:

 set str [string replace $str $length end ...]

If the string is already shorter than $length, it will not be touched.

There is the end case where [string length $str] > $length, but [string length $str] < $length + 3. Adding the ellipsis might make the string longer.


Category Characters | Category String Processing | Arts and crafts of Tcl-Tk programming