[web] Latin1 vs UTF8

Started by
2 comments, last by SiCrane 16 years, 1 month ago
Ok I'm having trouble. I'm getting Latin1 encoded strings in UTF-8 format. So loads of characters are "SQUARES" if u guys see what I mean. anyways, how do I convert these SQUARES into their UTF-8 correspondent. For example, I've already succeeded in converting new-line (VT) by doing a .Replace((char)0x0B, "<br/>\n") now I want to replace -, ` among others so they show up nicely in the UTF-8 coded mode. What do I do? ANSI: 697359 CASH JOHNNY HELLO SWEDEN, I’M JOHNNY CASH –EN COUNTRYLEGEND OCH HANS SVERIGEBESÖK 2007-06-21 Böcker 1 BOKK Johnny Cash lever i svenska hjärtan. Han älskade Sverige och vi älskade Johnny Cash som fåandra artister. Han var en trogen gäst hos oss under ett kvarts århundrade. Från publikrekordet iScandinavium 1971 till den sista bejublade turnén 1997, när han märkt av sjukdom erövrade enny ungdomlig publik. Johnny Cash gjorde ett stort avtryck i vårt land. Det är hög tid att berätta omhans svenska konserter, hans nära vänskap med svenska fans, hans aptit på Janssons frestelse,hans oväntade besök i Pingstkyrkan och inte minst hans unika framträdande för fångarna påÖsteråkersanstalten. I boken kommer vi stjärnan nära in på livet genom nygjorda intervjuer,tidstypiska citat, personliga upplevelser och ett bildmaterial utan motstycke. REV REV UTF-8: 697359 CASH JOHNNY HELLO SWEDEN, IӍ JOHNNY CASH ֋EN COUNTRYLEGEND OCH HANS SVERIGEBES׋ 2007-06-21 B礫er 1 BOKK Johnny Cash lever i svenska hj峴an. Han 孳kade Sverige och vi 孳kade Johnny Cash som f匡ndra artister. Han var en trogen g崴 hos oss under ett kvarts 注undrade. Fr殠publikrekordet iScandinavium 1971 till den sista bejublade turnꮠ1997, n岠han m峫t av sjukdom er緲ade enny ungdomlig publik. Johnny Cash gjorde ett stort avtryck i v泴 land. Det 岠h秠tid att ber嵴a omhans svenska konserter, hans n峡 v寳kap med svenska fans, hans aptit p塊anssons frestelse,hans ov寴ade bes章i Pingstkyrkan och inte minst hans unika framtr奡nde f粠f毧arna p化ster欥rsanstalten. I boken kommer vi stj峮an n峡 in p塬ivet genom nygjorda intervjuer,tidstypiska citat, personliga upplevelser och ett bildmaterial utan motstycke. REV REV EDIT: .Replace((char)150 + "", "-") to replace the - to UTF-8 correct one. Now only the ’
Advertisement
It might help if you mentioned what programming language you're using, what libraries, etc.
oh sorry :D haha

I'm using C#.NET

http://www.cyrillic.com/3dkbd/ansitable.html
am I supposed to do a REPLACE for all of those charactes to UTF-8? Seriously, there has to be an easier way. :)
Latin-1 characters have the property that their character values are the same as their unicode character values. However, the Latin-1 encoding is different from the UTF-8 encoding since values above 0x7f are encoded with two bytes. To convert a Latin-1 sequence into a UTF-8 sequence in C#, there are a couple of approaches. 1) take the byte array with the Latin-1 values and convert each byte into a char. This will yield a UTF-16 encoded string. Then use System.Text to convert the UTF-16 string into UTF-8. Alternately (2), create a new byte container and iterate over every byte in the Latin-1 source. If the byte value, V, is less than 0x80 place the byte into the new byte container. Otherwise place (0xc0 | (V >> 6)) and (0x80 | (V & 0x3f)) into the byte container.

This topic is closed to new replies.

Advertisement