Important alert: (current site time 7/15/2013 10:12:34 PM EDT)
 

VB icon

ANSI to Unicode

Email
Submitted on: 2/25/2002 12:08:12 PM
By: Lewis E. Moten III  
Level: Advanced
User Rating: By 2 Users
Compatibility: ASP (Active Server Pages), VbScript (browser/client side)
Views: 30514
author picture
(About the author)
 
     Converts from ANSI to Unicode very fast. Inspired by code found in UltraFastAspUpload by Cakkie (on PSC). This should work slightly faster then Cakkies due to how some of the code has been arranged.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: ANSI to Unicode
' Description:Converts from ANSI to Unicode very fast. Inspired by code found in UltraFastAspUpload by Cakkie (on PSC). This should work slightly faster then Cakkies due to how some of the code has been arranged.
' By: Lewis E. Moten III
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=7266&lngWId=4'for details.'**************************************

<%
' make a sample binary string of 2000 random letters
Dim test
Dim c
For i = 1 to 2000
	c = 65 + Int(Rnd * 25)
	test = test & ChrB(AscB(Chr(c)))
	If i Mod 4 = 0 Then
		test = test & ChrB(AscB(" "))
	End If
Next
Response.Write ANSIToUnicode(test)
Function ANSIToUnicode(ByRef pbinBinaryData)
	Dim lbinData	' Binary Data (ANSI)
	Dim llngLength	' Length of binary data (byte count)
	Dim lobjRs		' Recordset
	Dim lstrData	' Unicode Data
	' VarType Reference
	'8 = Integer (this is expected var type)
	'17 = Byte Subtype
	' 8192 = Array
	' 8209 = Byte Subtype + Array
	
	Set lobjRs = Server.CreateObject("ADODB.Recordset")
	If VarType(pbinBinaryData) = 8 Then
		' Convert integers(4 bytes) to Byte Subtype Array (1 byte)
		llngLength = LenB(pbinBinaryData)
		If llngLength = 0 Then
			lbinData = ChrB(0)
		Else
			Call lobjRs.Fields.Append("BinaryData", adLongVarBinary, llngLength)
			Call lobjRs.Open()
			Call lobjRs.AddNew()
			Call lobjRs.Fields("BinaryData").AppendChunk(pbinBinaryData & ChrB(0)) ' + Null terminator
			Call lobjRs.Update()
			lbinData = lobjRs.Fields("BinaryData").GetChunk(llngLength)
			Call lobjRs.Close()
		End If
	Else
		lbinData = pbinBinaryData
	End If
	' Do REAL conversion now!	
	llngLength = LenB(lbinData)
	If llngLength = 0 Then
		lstrData = ""
	Else
		Call lobjRs.Fields.Append("BinaryData", adLongVarChar, llngLength)
		Call lobjRs.Open()
		Call lobjRs.AddNew()
		Call lobjRs.Fields("BinaryData").AppendChunk(lbinData)
		Call lobjRs.Update()
		lstrData = lobjRs.Fields("BinaryData").Value
		Call lobjRs.Close()
	End If
				
	Set lobjRs = Nothing
	ANSIToUnicode = lstrData
	
End Function
%>


Other 102 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments
4/18/2002 11:40:52 AMGreat Job

you're better than many other sites (which even concentrate on ASP) I have seen.

keep going!
(If this comment was disrespectful, please report it.)

 
7/28/2003 6:19:23 AM

Another solution:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/graphics/h h/graphics/webfnc_8bs7.asp

(If this comment was disrespectful, please report it.)

 
12/2/2004 4:21:17 PM

It is quite crear but I it isn't waht I need
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.