post
poster: toraton
description: Ellipsizing Strings
language: Python
[download]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#!/usr/bin/python

string = "this is just a test string"
end = ""
max = 10

for word in string.split(' '):
    if len(end) + len(word) < max:
        end += " %s" % word
    else:
        end += " ..."
        break

print "string = %s" % string
print "short string = %s" % end