# Truncate problem

**URL:** <https://www.ruby-forum.com/t/truncate-problem/148925>\
**Category:** Rails\
**Created:** [September 18, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/truncate-problem/148925 "2008-09-18T12:13:17Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [September 18, 2008, 12:13pm UTC](https://www.ruby-forum.com/t/truncate-problem/148925/1 "2008-09-18T12:13:17Z")

</div>

Hi,  
In my application I am using a list box where i am showing different  
groups  
name. I am using  
\<%=truncate\_html\_strip\_textual\_wrap(group.name,28,28)%\>  
for truncating the name but it gives me problem when group name come  
like Shital’s friends from “Office” Group this

```
In list box it showing as a Shital's friends from & quote..
how to avoid such a thing? whats a proper way for handling such a

```

situations?

character like single quote, double quote, ampersand not truncated  
properly  
please give me a standers way for doing it.

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [September 18, 2008, 12:16pm UTC](https://www.ruby-forum.com/t/truncate-problem/148925/2 "2008-09-18T12:16:48Z")

</div>

On 18 Sep 2008, at 11:13, Sunny B. wrote:

> how to avoid such a thing? whats a proper way for handling such a  
> situations?
> 
> character like single quote, double quote, ampersand not truncated  
> properly

truncate before you escape html entities.

Fred

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [September 18, 2008, 12:30pm UTC](https://www.ruby-forum.com/t/truncate-problem/148925/3 "2008-09-18T12:30:23Z")

</div>

Could you explain with an example I am not understanding you?

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [September 18, 2008, 12:37pm UTC](https://www.ruby-forum.com/t/truncate-problem/148925/4 "2008-09-18T12:37:26Z")

</div>

On 18 Sep 2008, at 11:30, Sunny B. wrote:

> Could you explain with an example I am not understanding you?

Your problem is that truncating works on a character by character  
basis, which has the inbuilt assumption that it’s ok to cut off at any  
point.  
If you have for example & then it’s not find to cut in the middle  
of that. Therefore it is a lot easier to do any truncation before you  
stick in the & and other things like that (or write a version of  
truncate that understands entities and that they should not be messed  
with.

Fred

---

<div class="post-metadata">

**Author:** ![sunfish](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/96bed5/32.png) [@sunfish](https://www.ruby-forum.com/u/sunfish)\
**Post date:** [September 18, 2008, 12:49pm UTC](https://www.ruby-forum.com/t/truncate-problem/148925/5 "2008-09-18T12:49:29Z")

</div>

Ok, Thanks for suggestion  
do you know any JavaScript for handling such issue I am understanding  
it  
correctly.
