List Info

Thread: -=(ASP-Support-Group)=- Re: Character encoding problem with AJAX




-=(ASP-Support-Group)=- Re: Character encoding problem with AJAX
country flaguser name
United States
2008-03-02 11:30:27

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&quot; 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-Groupyahoogroups.com, "Tony Cheetham&quot; <Tony...>
wrote:
>
&gt; Well that got all messed up, please see the attached file for
properly
> formatted code..
&gt;
> TonyHome
>;
> Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum
saxum immane
> mittam
&gt; ----- Original Message -----
> From: "Tony Cheetham&quot; <Tony...>
> To: < ASP-Support-Group%40yahoogroups.com">ASP-Support-Groupyahoogroups.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
&gt; 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,
&gt; enough patronising background, the fix..
&gt;
> 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
&gt; 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
&gt;
> ' init stream
&gt; Set objStream = New ADODB.Stream
> objStream.Charset = "utf-8"
&gt; objStream.Mode = adModeReadWrite
>; objStream.Type = adTypeBinary
> objStream.Open
>
> ' write bytes into stream
&gt; objStream.Write data
>; objStream.Flush
>;
> ' rewind stream and read text
>; objStream.Position = 0
> objStream.Type = adTypeText
> strTmp = objStream.ReadText
>
> ' close up and return
&gt; objStream.Close
>; ConvertUtf8BytesToString = strTmp
&gt;
> 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&quot;)
&gt; 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
&gt; Dim data() As Byte
>; Dim strTmp As String
&gt;
> ' define test data as base64 and decode to array of bytes
&gt; strB64 = "R3JlZXRpbmdzIGFuZCBTYWx1dGF0aW9uISAo4oKsKSBhbmQgc29";
> strB64 = strB64
& "tZSBVcmR1OiDaqdix2KfahtuMINm+2Kfaqdiz2KrYp9mG24w=&quot;
> data = DecodeBase64(strB64)
>
> ' convert from utf-8 to string
&gt; strTmp = ConvertUtf8BytesToString(data)
>
> ' convert back to bytes
&gt; data = ConvertStringToUtf8Bytes(strTmp)
>
>
> TonyHome
>;
> Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum
saxum immane
&gt; mittam
&gt; ----- Original Message -----
> From: "g5sev" <g5sev...>
> To: < ASP-Support-Group%40yahoogroups.com">ASP-Support-Groupyahoogroups.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
&gt; in this situation. I've been trying to find an equivalent of ICONV
for
&gt; ASP all over the Internet - no luck, I wonder am I the only ASP
> programmer using cyrillic and AJAX?
&gt; And no, I am not willing to redo the whole site in UTF-8 - first
&gt; because it's alot of work, and second will double my database in
size
> since each character will take not 1 but 2 bytes.
&gt;
> Any suggestions will be appreciated.
> George
&gt;
>
>
> Group homepage is here:
&gt; 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-unsubscribeyahoogroups.com and cross your
fingers
> because Yahoo is 5h1te.
&gt;
> Yahoo! Groups Links
&gt;
>
>
>
>
>
> Group homepage is here:
&gt; 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-unsubscribeyahoogroups.com and cross your
fingers
> because Yahoo is 5h1te.
&gt;
> Yahoo! Groups Links
&gt;

__._,_.___
.

__,_._,___
Re: -=(ASP-Support-Group)=- Re: Character encoding problem with AJAX
country flaguser name
United States
2008-03-02 14:52:23

Sorry, I guess I always assume people are typing English. ASP won't deal
with anything that's not ANSI.

TonyHome

Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum saxum immane
mittam
----- Original Message -----
From: "g5sev" < g5sev%40yahoo.com">g5sevyahoo.com>
To: < ASP-Support-Group%40yahoogroups.com">ASP-Support-Groupyahoogroups.com>
Sent: Sunday, March 02, 2008 5:30 PM
Subject: -=(ASP-Support-Group)=- Re: Character encoding problem with AJAX

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&quot; 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-Groupyahoogroups.com, "Tony Cheetham&quot; <Tony...>
wrote:
&gt;
> Well that got all messed up, please see the attached file for
properly
> formatted code..
&gt;
> TonyHome
>;
> Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum
saxum immane
&gt; mittam
&gt; ----- Original Message -----
> From: "Tony Cheetham&quot; <Tony...>
> To: < ASP-Support-Group%40yahoogroups.com">ASP-Support-Groupyahoogroups.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
&gt; 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..
&gt;
> 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
&gt;
> ' init stream
&gt; Set objStream = New ADODB.Stream
> objStream.Charset = "utf-8"
&gt; objStream.Mode = adModeReadWrite
>; objStream.Type = adTypeBinary
> objStream.Open
>
> ' write bytes into stream
&gt; objStream.Write data
>; objStream.Flush
>;
> ' rewind stream and read text
>; objStream.Position = 0
> objStream.Type = adTypeText
> strTmp = objStream.ReadText
>
> ' close up and return
&gt; objStream.Close
>; ConvertUtf8BytesToString = strTmp
&gt;
> 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&quot;)
&gt; 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
&gt; Dim data() As Byte
>; Dim strTmp As String
&gt;
> ' define test data as base64 and decode to array of bytes
&gt; strB64 = "R3JlZXRpbmdzIGFuZCBTYWx1dGF0aW9uISAo4oKsKSBhbmQgc29";
> strB64 = strB64
&amp; "tZSBVcmR1OiDaqdix2KfahtuMINm+2Kfaqdiz2KrYp9mG24w=&quot;
> data = DecodeBase64(strB64)
>
&gt; ' convert from utf-8 to string
&gt; strTmp = ConvertUtf8BytesToString(data)
>
&gt; ' convert back to bytes
&gt; data = ConvertStringToUtf8Bytes(strTmp)
>
>
> TonyHome
>;
> Catapultam habeo. Nisi pecuniam omnem mihi dabis, ad caput tuum
saxum immane
&gt; mittam
&gt; ----- Original Message -----
> From: "g5sev" <g5sev...>
> To: < ASP-Support-Group%40yahoogroups.com">ASP-Support-Groupyahoogroups.com>
> Sent: Saturday, March 01, 2008 7:30 PM
> Subject: -=(ASP-Support-Group)=- Character encoding problem with
AJAX
>
>
> Hello everyone,
>
&gt; 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
&gt; 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?
&gt; And no, I am not willing to redo the whole site in UTF-8 - first
&gt; because it's alot of work, and second will double my database in
size
> since each character will take not 1 but 2 bytes.
&gt;
> Any suggestions will be appreciated.
> George
&gt;
>
>
&gt; Group homepage is here:
&gt; 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-unsubscribeyahoogroups.com and cross your
fingers
> because Yahoo is 5h1te.
&gt;
> Yahoo! Groups Links
&gt;
>
>
>;
>
>
> Group homepage is here:
&gt; 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-unsubscribeyahoogroups.com and cross your
fingers
> because Yahoo is 5h1te.
&gt;
> Yahoo! Groups Links
&gt;

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-unsubscribeyahoogroups.com and cross your fingers
because Yahoo is 5h1te.

Yahoo! Groups Links

__._,_.___
.

__,_._,___
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )