Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

convert asp string to UTF-8?

Guest
May 08, 2007 May 08, 2007
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.
TOPICS
Code , How to
16.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
May 08, 2007 May 08, 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.


Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
May 08, 2007 May 08, 2007
i recommend you to use notepad++
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
May 10, 2007 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))

%>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
May 12, 2007 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
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Jul 22, 2008 Jul 22, 2008
or use this for asp pages:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 13, 2017 Aug 13, 2017
LATEST

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)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines