通常のコードページで UTF-8 -> SHIFT_JIS |
|
まず、クライアントから受けた「あ」という UTF-8 文字を表示してみます。
|
<%
Response.ContentType = "text/html"
Response.Charset= "shift_jis"
Response.ExpiresAbsolute=#May 31,2000 23:59:59#
Set Stream = Server.CreateObject( "ADODB.Stream" )
Set CAPIUtil = Server.CreateObject( "CAPICOM.Utilities" )
Set MyData = Server.CreateObject("Scripting.Dictionary")
' **********************************************************
' UTF-8 入力文字列の変換
' **********************************************************
Function ConvertQueryString()
Dim InData,nData,aData,I,strChar
Stream.Open
InData = Split( Request.QueryString, "&" )
For nData = 0 to Ubound( InData )
Stream.Position = 0
Stream.SetEOS
Stream.Charset = "utf-8"
Stream.Type = 1 ' バイナリ
aData = Split( InData(nData), "=" )
strChar =""
For I = 1 to Len( aData(1) )
strChar = Mid( aData(1), I, 1 )
if strChar = "%" then
I = I + 1
strChar = ChrB(CLng( "&H" & Mid( aData(1), I, 2 ) ))
I = I + 1
else
strChar = ChrB(Asc(strChar))
end if
ByteArray = CAPIUtil.BinaryStringToByteArray( strChar )
Stream.Write ByteArray
Next
Stream.Position = 0
Stream.Type = 2 ' テキスト
MyData( aData(0) ) = Stream.ReadText()
Next
Stream.Close
End Function
Call ConvertQueryString()
' shift_jis で比較
if MyData("value") = "送信" then
sjis = "送信を受信しました"
end if
Response.Write sjis
%>
| |
|
|
通常のコードページで UTF-8 -> EUC-JP |
|
|
<%
Response.ContentType = "text/html"
Response.Charset= "euc-jp"
Response.ExpiresAbsolute=#May 31,2000 23:59:59#
Set Stream = Server.CreateObject( "ADODB.Stream" )
Set CAPIUtil = Server.CreateObject( "CAPICOM.Utilities" )
Set MyData = Server.CreateObject("Scripting.Dictionary")
' **********************************************************
' UTF-8 入力文字列の変換
' **********************************************************
Function ConvertQueryString()
Dim InData,nData,aData,I,strChar
Stream.Open
InData = Split( Request.QueryString, "&" )
For nData = 0 to Ubound( InData )
Stream.Position = 0
Stream.SetEOS
Stream.Charset = "utf-8"
Stream.Type = 1 ' バイナリ
aData = Split( InData(nData), "=" )
strChar =""
For I = 1 to Len( aData(1) )
strChar = Mid( aData(1), I, 1 )
if strChar = "%" then
I = I + 1
strChar = ChrB(CLng( "&H" & Mid( aData(1), I, 2 ) ))
I = I + 1
else
strChar = ChrB(Asc(strChar))
end if
ByteArray = CAPIUtil.BinaryStringToByteArray( strChar )
Stream.Write ByteArray
Next
Stream.Position = 0
Stream.Type = 2 ' テキスト
MyData( aData(0) ) = Stream.ReadText()
Next
Stream.Close
End Function
' ************************************************
' 内部コードを EUC-JP へ変換
' ************************************************
function ConvCharset( strValue )
Stream.Open
Stream.Position = 0
Stream.SetEOS
Stream.Type = 2 ' テキスト
Stream.Charset = "euc-jp"
Stream.WriteText strValue
Stream.Position = 0
Stream.Type = 1 ' バイナリ
ConvCharset = Stream.Read()
Stream.Close
end function
Call ConvertQueryString()
euc = ""
' shift_jis で比較
if MyData("value") = "送信" then
euc = ConvCharset( "送信を受信しました" )
end if
Response.BinaryWrite euc
%>
| |
|
|
通常のコードページで UTF-8 -> UTF-8 |
EUC-JP (CODEPAGE=51932) で UTF-8 -> EUC-JP |
|
|
<%
CODEPAGE=51932
Response.ContentType = "text/html"
Response.Charset= "euc-jp"
Response.ExpiresAbsolute=#May 31,2000 23:59:59#
Set Stream = Server.CreateObject( "ADODB.Stream" )
Set CAPIUtil = Server.CreateObject( "CAPICOM.Utilities" )
Set MyData = Server.CreateObject("Scripting.Dictionary")
' **********************************************************
' UTF-8 入力文字列の変換
' **********************************************************
Function ConvertQueryString()
Dim InData,nData,aData,I,strChar
Stream.Open
InData = Split( Request.QueryString, "&" )
For nData = 0 to Ubound( InData )
Stream.Position = 0
Stream.SetEOS
Stream.Charset = "utf-8"
Stream.Type = 1 ' バイナリ
aData = Split( InData(nData), "=" )
strChar =""
For I = 1 to Len( aData(1) )
strChar = Mid( aData(1), I, 1 )
if strChar = "%" then
I = I + 1
strChar = ChrB(CLng( "&H" & Mid( aData(1), I, 2 ) ))
I = I + 1
else
strChar = ChrB(Asc(strChar))
end if
ByteArray = CAPIUtil.BinaryStringToByteArray( strChar )
Stream.Write ByteArray
Next
Stream.Position = 0
Stream.Type = 2 ' テキスト
strChar = Stream.ReadText()
Stream.Position = 0
Stream.SetEOS
Stream.Type = 2 ' テキスト
Stream.Charset = "euc-jp"
Stream.WriteText strChar
Stream.Position = 0
Stream.Charset = "shift_jis"
MyData( aData(0) ) = Stream.ReadText()
Next
Stream.Close
End Function
Call ConvertQueryString()
ujis = ""
' ujis で比較
if MyData("value") = "送信" then
ujis = "送信を受信しました"
end if
Response.Write ujis
%>
| |
|
|
UTF-8 (CODEPAGE=65001 ) で UTF-8 -> UTF-8 |
|