on 2012 Jul 16 12:55 PM
What is the best practise for limiting text results to a certain number of chars?
e.g. Select left(name,20) from table
Request clarification before answering.
The above works but is fairly primitive as it chops words. The more elegant way to do that is to search backwards from the end of the desired truncation length and look for white space or punctuation and replace it with ellipsis (...) For larger text fields we sometimes supply the character count in parenthesis with the ellipsis.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ah, "more elegant" will combine nicely with "regex" to search for whitespace, punctuation and the like...
I guess that will have a BreckRant® started:)
@Glenn: Don't get me wrong, I agree on your user-friendly approach - I just thought about how to solve that within SA, and read Breck's comments...
I think we have some SA code we use for this - I'll try to post it later. THis is a very common requirement in reports when there can be a lot of text.
Would be great if you can come up with something
Here's what happens when *I* promise something in advance of delivering...
Promise code sample that I "know" I have.
Search fruitlessly for code sample that is lost, or perhaps once thought of but never actually written (I'm old, forgetful, etc).
Write code sample from scratch, test, etcetera, finally deliver it.
Rush to catch up with the work I was supposed to be doing.
Which is why I stopped promising stuff 🙂
I was not criticising, I was sharing advice... it's the reason I no longer say "this is the first article in a series" unless the whole series has been written... it's a jinx thing 🙂
User | Count |
---|---|
87 | |
10 | |
9 | |
9 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.