Pages

Monday, August 6, 2007

ASP Escape Mode

Function EscapeCode(p_Message)
Dim m_char,m_asc,m_hex
Dim m_temp
Dim a_arc()
Dim i
ReDim a_arc(Len(p_Message))
For i = 0 To Len(p_Message) -1
m_char = Mid(p_Message,i+1,1)
m_asc = AscW(m_char)
If m_asc < 255 Then
If (m_char = "*") Or(m_char = "+") _
Or(m_char >= "-" And m_char <= "9" ) _
Or(m_char >= "@" And m_char <= "Z" ) _
Or(m_char = "_") _
Or(m_char >= "a" And m_char <= "z" ) Then
a_arc(i) = m_char
Else
m_temp = Hex(m_asc)
If Len(m_temp) = 1 Then
a_arc(i) = "%0" & m_temp
ElseIf Len(m_temp) = 2 Then
a_arc(i) = "%" & m_temp
Else
a_arc(i) = "%u" & m_temp
End If
End If
Else
m_temp = Hex(m_asc)
If Len(m_temp) = 1 Then
a_arc(i) = "%u000" & m_temp
ElseIf Len(m_temp) = 2 Then
a_arc(i) = "%u00" & m_temp
ElseIf Len(m_temp) = 3 Then
a_arc(i) = "%u0" & m_temp
Else
a_arc(i) = "%u" & m_temp
End If
End If
Next
EscapeCode = Join(a_arc,"")
End Function

UCS-2 to Gb code

Function ReadC(HWord,TStartC)

for X= 0 TO (((Len(Trim(HWord))-TStartC)/4)-1)
ASplit = Mid(Replace(Right(HWord, Len(Trim(HWord))-TStartC), " ", ""),(4*X+1),4)

IF ASplit > "0000" and ASplit < "00FF" THEN
CText = Chr(CLng("&H" & ASplit))
ELSE
CText = Unescape("%u" & ASplit)
END IF

FText = FText & CText
Next

ReadC = Left(HWord, TStartC) & FText

End Function

String to UCS-2 Convert

Function Convert(Word)
For i = 1 to Len(Word)
IF Asc(Mid(Word,i,1)) > 0 and Asc(Mid(Word,i,1)) < 256 THEN
CVT = "00" & Hex(Asc(Mid(Word,i,1))) 'Convert AlphaNumeric
ELSE
CVT = Replace(Escape(Mid(Word,i,1)),"%u", "") 'Convert Chinese Character
END IF

TMsg = TMsg & CVT
Next
Convert = TMsg
END Function