Ideal method to truncate a string with ellipsis

I like the idea of letting “thin” characters count as half a character. Simple and a good approximation. The main issue with most ellipsizings however, are (imho) that they chop of words in the middle. Here is a solution taking word-boundaries into account (but does not dive into pixel-math and the Swing-API). private final static … Read more

text-overflow:ellipsis in Firefox 4? (and FF5)

Spudley, you could achieve the same thing by writing a small JavaScript using jQuery: var limit = 50; var ellipsis = “…”; if( $(‘#limitedWidthTextBox’).val().length > limit) { // -4 to include the ellipsis size and also since it is an index var trimmedText = $(‘#limitedWidthTextBox’).val().substring(0, limit – 4); trimmedText += ellipsis; $(‘#limitedWidthTextBox’).val(trimmedText); } I understand … Read more

CSS text-overflow: ellipsis; not working?

text-overflow:ellipsis; only works when the following are true: The element’s width must be constrained in px (pixels). Width in % (percentage) won’t work. The element must have overflow:hidden and white-space:nowrap set. The reason you’re having problems here is because the width of your a element isn’t constrained. You do have a width setting, but because … Read more

Truncate a string to first n characters of a string and add three dots if any characters are removed

//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) … Read more

Insert ellipsis (…) into HTML tag if content too wide

The following CSS only solution for truncating text on a single line works with all browers listed at http://www.caniuse.com as of writing with the exception of Firefox 6.0. Note that JavaScript is totally unnecessary unless you need to support wrapping multiline text or earlier versions of Firefox. .ellipsis { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; … Read more

What is the ellipsis (…) for in this method signature?

Those are Java varargs. They let you pass any number of objects of a specific type (in this case they are of type JID). In your example, the following function calls would be valid: MessageBuilder msgBuilder; //There should probably be a call to a constructor here 😉 MessageBuilder msgBuilder2; msgBuilder.withRecipientJids(jid1, jid2); msgBuilder2.withRecipientJids(jid1, jid2, jid78_a, someOtherJid); … Read more

How to use R’s ellipsis feature when writing your own function?

I read answers and comments and I see that few things weren’t mentioned: data.frame uses list(…) version. Fragment of the code: object <- as.list(substitute(list(…)))[-1L] mrn <- is.null(row.names) x <- list(…) object is used to do some magic with column names, but x is used to create final data.frame. For use of unevaluated … argument look … Read more