Thanks for reply. I write this little function to do what I need.
<%= getStringEncodedToHtml ( "h?h?" ) %> ( function below )
become
héhà
I''m new to RoR and Ruby. Someone could tell me if this function could
be
more optimized ?
I use has_key but perhaprs there is a faster method.
Thanks
def getStringEncodedToHtml ( pString )
str = String.new( pString )
map = {
34 => "quot", # "
38 => "amp", # &
39 => "apos", # ''
60 => "lt", # <
62 => "gt", # >
169 => "copy", # ?
171 => "laquo", # ?
174 => "reg", # ?
187 => "raquo", # ?
192 => "Agrave", # ?
194 => "Acirc", # ?
198 => "AElig", # ?
199 => "Ccedil", # ?
200 => "Egrave", # ?
201 => "Eacute", # ?
202 => "Ecirc", # ?
203 => "Euml", # ?
206 => "Icirc", # ?
207 => "Iuml", # ?
212 => "Ocirc", # ?
214 => "Ouml", # ?
217 => "Ugrave", # ?
219 => "Ucirc", # ?
220 => "Uuml", # ?
224 => "agrave", # ?
225 => "aacute", # ?
226 => "acirc", # ?
228 => "auml", # ?
230 => "aelig", # ?
231 => "ccedil", # ?
232 => "egrave", # ?
233 => "eacute", # ?
234 => "ecirc", # ?
235 => "euml", # ?
238 => "icirc", # ?
239 => "iuml", # ?
244 => "ocirc", # ?
246 => "ouml", # ?
249 => "ugrave", # ?
251 => "ucirc", # ?
252 => "uuml", # ?
}
lng = str.length
while lng > 0
if map.has_key?( str[ lng ] )
str[ lng ] = "&" + map[ str[ lng ] ] + ";"
end
lng -= 1
end
return str
end
> If you''re using UTF-8, you can try my tip for converting UTF-8
> characters in to numerical
> HTML entities. These take the form of &#XXXX; and describe a unicode
> character code;
> works the same way as named entities like é do.
>
> See rails.techno-weenie.net/tip/2005/12/30
> unicode_escaping_h_variant
>
> -Thomas
>
>
> Am 30.12.2005 um 20:46 schrieb oo00oo:
>
>> I try to find an function to convert characters in html chars.
"?"
>> become "é"
>>
>> There is something in RoR 1.0 to do that ?
>> _______________________________________________
>> Rails mailing list
>> Rails@lists.rubyonrails.org
>> lists.rubyonrails.org/mailman/listinfo/rails
>
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> lists.rubyonrails.org/mailman/listinfo/rails
>
>