String as punycode encoded string. You can directly convert data from/to any charset to punycode using this property.">
Returns unicode String as punycode encoded string. You can directly convert data from/to any charset to punycode using this property.
vPunycode = ByteArray.Punycode
ByteArray.Punycode = vPunycode
String
Please use unicode code pages (utf-8 or utf-16, see ConvertCodePages) to work with all possible unicode characters.
See live sample of this method
ByteArray - Punycode - unicode conversions |
| Short functions to encode/decode string<->punycode data. You can use these functions as an Internationalized Domain Names VBScript converter. See Live punycode idn decoder/encoder. |
Dim m_BA
Function BA
If IsEmpty(m_BA) Then Set m_BA = CreateObject("ScriptUtils.ByteArray"): m_BA.CharSet = "utf-8"
Set BA = m_BA
End Function
'conversion from unicode string to punycode
Function ToPUNYCODE(Data)
Dim Outdata
BA.String = Data
Outdata = "<div>ToPUNYCODE : Punycode representation of '" & _
Data & "' string :<div style=background-color:yellow;color:blue>"
Outdata = Outdata & "<b>" & BA.Punycode & "</b>"
Outdata = Outdata & "</div></div>"
ToPUNYCODE = Outdata
End Function
'conversion from punycode string (OLE String) to a UNICODE string
Function FromPUNYCODE(Data)
Dim Outdata
On Error Resume Next
BA.Punycode = Data
If Err=0 Then
Outdata = "<div>FromPUNYCODE : Unicode string :<div style=background-color:yellow;color:blue>"
Outdata = Outdata & "<b>" & BA.String & "</b>"'write the UTF representation
Outdata = Outdata & "</div></div>"
Else
Outdata = "<div style=background-color:red;color:yellow>FromPUNYCODE:Punycode string '" & _
Data & "' has no unicode representation.</div>"
End If
FromPUNYCODE = Outdata
End Function
'conversion of a host name (www.anychar.com) to a punycode idn version (www.xn--translated.com)
Function ToIDN(Data)
Dim Outdata, pData, partuni, partpuny
pData = Split(Data, ".")
For Each partuni In pData
BA.String = partuni
partpuny = BA.Punycode
If Right(partpuny,1)<>"-" Then partpuny = "xn--" & partpuny Else partpuny = partuni
Outdata = Outdata & partpuny & "."
Next
Outdata = Left(Outdata, Len(Outdata)-1)
ToIDN = "<div>ToIDN : IDN representation of '" & _
Data & "' string :<div style=background-color:yellow;color:blue><b>" & _
Outdata & "</b></div></div>"
End Function
'conversion of a host name in idn punycode (www.xn--translated.com)
' to an unicode string (www.anychar.com)
Function FromIDN(ByVal Data)
Dim Outdata, pData, partuni, partpuny
Data = LCase(Data)
pData = Split(Data, ".")
For Each partpuny In pData
If Left(partpuny,4)="xn--" Then
BA.Punycode = Mid(partpuny, 5)
partuni = Ba.String
Else
'on error resume next
'BA.Punycode = partpuny
Dim re :set re = New RegExp
re.pattern = "^[-a-zA-Z0-9]+$"
If re.Test(partpuny) Then
partuni = partpuny
Else
partuni = "<font Color=red>error (" & partpuny & ")</Font>"
End If
End If
Outdata = Outdata & partuni & "."
Next
Outdata = Left(Outdata, Len(Outdata)-1)
FromIDN = "<div>FromIDN : Unicode representation of IDN '" & Data & _
"' :<div style=background-color:yellow;color:blue><b>" & _
Outdata & "</b></div></div>"
End Function |
ByteArray.HexString, ByteArray.Base64
This property is using VeriSign XCode (encode/decode) IDN Library A library for encoding / decoding of domain strings. (c) VeriSign Inc., 2003, All rights reserved
Find, FindRev, CharSetConvert, Left, Mid, ReadFrom, Right, SaveAs, SetSize
Base64, ByteArray, CodePage, HexString, CharSet, Length, Punycode, String
Works with safearray binary data - save/restore binary data from/to a disk, convert to a string/hexstring, codepage/charset conversions, Base64 conversion, etc.
ByteArray is a COM class specially designed to work with Microsoft Windows Scripting engines - VB Script and JScript in Active Server Pages or WSH and in CHM or HTA applications. It also works with VB Net, Visual basic (VBA - VB 5, VB 6, Word, Excel, Access, …), C#, J#, C++, ASP, ASP.Net, Delphi and with T-SQL OLE functions - see Use ByteArray object article. You can also use the object in other programming environments with COM support, such is PowerBuilder.
Source code for ByteArray is available within distribution license, please see License page for ASP file upload and ScriptUtilities.
© 1996 - 2009 Antonin Foller, Motobit Software | About, Contacts | e-mail: info@pstruh.cz