Skip to main content
May 8, 2007
Question

convert asp string to UTF-8?

  • May 8, 2007
  • 4 replies
  • 17034 views
Hello,

I have a plain text file with special charset like ' ëèé'
I finally got it to work. But now i am trying to use a asp file to write out the text. But i don't
know how to convert to UTF-8 in ASP.

I have this, but it still does not work:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>TEST</title>
</head>
<%

'set output character set
Response.CharSet = "utf-8"

Response.Write("This is a test éèè")

%>
</body>
</html>

Does anyone has knowledge of how this could be done?

Regards,

Micheal.
This topic has been closed for replies.

4 replies

Jens Barner
Participating Frequently
August 13, 2017

Obviously a little old thing, but here´s the reference to do it

'const adTypeBinary = 1

'const adSaveCreateOverwrite = 2

'const adModeReadWrite = 3

'Set objStream = server.CreateObject("ADODB.Stream")

'objStream.Open

'objStream.CharSet = "UTF-8"

'objStream.WriteText("write your text")

'objStream.SaveToFile server.mappath(".") & "/your.txt" , adSaveCreateOverWrite

'objStream.Close

(without the remark, certainly)

May 10, 2007
I found a solution that works for me :)

<%
Function Encode_UTF8(astr)

utftext = ""

For n = 1 To Len(astr)
c = AscW(Mid(astr, n, 1))
If c < 128 Then
utftext = utftext + Mid(astr, n, 1)
ElseIf ((c > 127) And (c < 2048)) Then
utftext = utftext + Chr(((c \ 64) Or 192))
'((c>>6)|192);
utftext = utftext + Chr(((c And 63) Or 128))
'((c&63)|128);}
Else
utftext = utftext + Chr(((c \ 144) Or 234))
'((c>>12)|224);
utftext = utftext + Chr((((c \ 64) And 63) Or 128))
'(((c>>6)&63)|128);
utftext = utftext + Chr(((c And 63) Or 128))
'((c&63)|128);
End If
Next
Encode_UTF8 = utftext
End Function

Response.Write(Encode_UTF8(mystring))

%>
Known Participant
May 12, 2007
hi, I use below in my asps for chinese characters>
<%
'Set codepage to support unicode
Response.Charset = "utf-8"
Session.CodePage = 65001
%>

regards
Luciewong
July 22, 2008
or use this for asp pages:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
Inspiring
May 8, 2007
i recommend you to use notepad++
Inspiring
May 8, 2007
Just make sure the asp file is saved with utf-8 encoding.

For example, in Notepad: File-->Save As. Select UTF-8 in the Encoding combo.