Thanks alot Tony. Very valuable information. Meantime I created my
own function to convert strings built from ANSI + Cyrillic characters
encoded in UTF-8 to windows-1251 (Cyrillic-window). My site is using
either cyrillic or latin characters so that should be enough and I
tested it seems to work fine. However, I wanted to be on the safe
side and use something provided in ASP so I will research carefully
your suggestion and change my solution accordingly. Can't help to
notice though how easy this is done in PHP with just a single
function, which if I am not mistaken also exists in other webdev
languages.
One more thing: you said "Basically if your not using any strange
character, then you should be able
> to just dump the data into a string, and ASP will do it for you."
what do you mean by that?
If I am using only ANSI chars (with ascii < = 127 ) then I don't have
to do anything since they are represented in the same way in both UTF-
8 and windows-1251 - is that what you mean? But with the cyrillic
chars (which are not exactly that "strange" - probably some of most
used after latin) there should be some kind of conversion (for
example russian letter "A" is represented in UTF-8 by two bytes D0 90
and by 1 byte C0 in windows-1251) - how will ASP "do it for me" - am
I missing something?
Thanks again for your help.
--- In ASP-Support-Group%40yahoogroups.com">ASP-Support-Group
yahoogroups.com, "Tony Cheetham" <Tony
...>
wrote:
>
> Well that got all messed up, please see the attached file for
properly
> formatted code..
>
> Tony
Home
>
> Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum
saxum immane
> mittam
> ----- Original Message -----
> From: "Tony Cheetham" <Tony
...>
> To: < ASP-Support-Group%40yahoogroups.com">ASP-Support-Group
yahoogroups.com>
> Sent: Saturday, March 01, 2008 11:18 PM
> Subject: Re: -=(ASP-Support-Group)=- Character encoding problem
with AJAX
>
>
> Well it's important to remember ajax is really a method of
interaction, as
> apposed to an actual language or object. What your really having
an issue
> with is xmlhttp, or xmlhttprequest. And as the name suggest, these
are XML
> based protocols and therefore you should really always use UTF-8.
Ok,
> enough patronising background, the fix..
>
> Basically if your not using any strange character, then you should
be able
> to just dump the data into a string, and ASP will do it for you.
But I
> presume you've tried that and come across a problem, so you can use
the
> ADODB stream object to convert it. This does require you
converting your
> string into a byte array first, but it's a reliable method that
uses only
> inbuilt asp objects(There are a few external objects around that
will do all
> this a lot easier).
>
> The decode function
> Public Function ConvertUtf8BytesToString(ByRef data() As Byte) As
String
>
> Dim objStream As ADODB.Stream
> Dim strTmp As String
>
> ' init stream
> Set objStream = New ADODB.Stream
> objStream.Charset = "utf-8"
> objStream.Mode = adModeReadWrite
> objStream.Type = adTypeBinary
> objStream.Open
>
> ' write bytes into stream
> objStream.Write data
> objStream.Flush
>
> ' rewind stream and read text
> objStream.Position = 0
> objStream.Type = adTypeText
> strTmp = objStream.ReadText
>
> ' close up and return
> objStream.Close
> ConvertUtf8BytesToString = strTmp
>
> End Function
> The base64 converterPrivate Function DecodeBase64(ByVal strData As
String)
> As Byte() Dim objXML As MSXML2.DOMDocument Dim objNode As
> MSXML2.IXMLDOMElement ' help from MSXML Set objXML = New
> MSXML2.DOMDocument Set objNode = objXML.createElement("b64")
> objNode.dataType = "bin.base64" objNode.Text = strData
DecodeBase64 =
> objNode.nodeTypedValue ' thanks, bye Set objNode =
Nothing Set
> objXML = NothingEnd FunctionYour actual conversion code.. Dim
strB64 As
> String
> Dim data() As Byte
> Dim strTmp As String
>
> ' define test data as base64 and decode to array of bytes
> strB64 = "R3JlZXRpbmdzIGFuZCBTYWx1dGF0aW9uISAo4oKsKSBhbmQgc29"
> strB64 = strB64
& "tZSBVcmR1OiDaqdix2KfahtuMINm+2Kfaqdiz2KrYp9mG24w="
> data = DecodeBase64(strB64)
>
> ' convert from utf-8 to string
> strTmp = ConvertUtf8BytesToString(data)
>
> ' convert back to bytes
> data = ConvertStringToUtf8Bytes(strTmp)
>
>
> Tony
Home
>
> Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum
saxum immane
> mittam
> ----- Original Message -----
> From: "g5sev" <g5sev
...>
> To: < ASP-Support-Group%40yahoogroups.com">ASP-Support-Group
yahoogroups.com>
> Sent: Saturday, March 01, 2008 7:30 PM
> Subject: -=(ASP-Support-Group)=- Character encoding problem with
AJAX
>
>
> Hello everyone,
>
> My website is in windows-1251 encoding and everything in the db is
> stored in windows-1251. Now I am trying to use AJAX and as I
understand
> AJAX sends the request in UTF-8. So I will need to convert UTF-8 to
> windows-1251 once I get the request and then store in db. There is a
> function in PHP iconv doing that, but what do we (ASP programmers)
do
> in this situation. I've been trying to find an equivalent of ICONV
for
> ASP all over the Internet - no luck, I wonder am I the only ASP
> programmer using cyrillic and AJAX?
> And no, I am not willing to redo the whole site in UTF-8 - first
> because it's alot of work, and second will double my database in
size
> since each character will take not 1 but 2 bytes.
>
> Any suggestions will be appreciated.
> George
>
>
>
> Group homepage is here:
> http://groups.yahoo.com/group/ASP-Support-Group
>
> To unsubscribe from this group, send an email to:
> ASP-Support-Group-unsubscribe%40yahoogroups.com">ASP-Support-Group-unsubscribe
yahoogroups.com and cross your
fingers
> because Yahoo is 5h1te.
>
> Yahoo! Groups Links
>
>
>
>
>
>
> Group homepage is here:
> http://groups.yahoo.com/group/ASP-Suppor