Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Ascii to HEX in Unicode fonts
Message
From
10/02/2014 06:06:46
 
 
To
10/02/2014 05:32:16
Reza Meamar
Homa Programming Group
Shiraz, Iran
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 7 SP1
OS:
Windows XP SP3
Network:
Windows 2003 Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01593811
Message ID:
01593824
Views:
32
>>>>>>>Dear All,
>>>>>>>I am using from Persian font. ( similar to Arabic )
>>>>>>>I need to calculate HEX value of each character of my string.
>>>>>>>So, ascii code of my character must be based on UNICODE.
>>>>>>>For example
>>>>>>>?asc(“م”) && Return 227 => HEX=E3
>>>>>>>
>>>>>>>But in Unicode, it must return 1605 => HEX=0645
>>>>>>>
>>>>>>>How I can do this conversion?
>>>>>>
>>>>>>try
>>>>>>
>>>>>>(1) Conversion from code page 1256 (arabic) to UTF-16 ( little endian)
>>>>>>
>>>>>>data =chr (227)
>>>>>>utf16 =Strconv(m.data , 5, 1256, 1)
>>>>>>
>>>>>>
>>>>>>If you want UTF-16 big endian, you'll have to reverse the bytes of utf16
>>>>>>(2) utf-16 to hex
>>>>>>
>>>>>>hex = strconv(utf16, 15)
>>>>>>?hex && 4506
>>>>>>
>>>>>
>>>>>Dear gregory,
>>>>>an error occurred in line
>>>>>utf16 =Strconv(m.data , 5, 1256, 1)
>>>>
>>>>What error ?
>>>
>>>in
>>>utf16 =Strconv(m.data , 5, 1256, 1)
>>>ERROR : TOO MANY ARGUMENTS.
>>>
>>>and if i changed to
>>>utf16 =Strconv(m.data , 5, 1256)
>>>ERROR : INVALID LOCALE ID.
>>>
>>>I am using from VFP7
>>
>>
>>I don't have vfp7 to test
>>
>>Try
>>
>>utf16 =Strconv(m.data , 5)
>>
>>
>>
>>or the function StringToUTF16() which uses api here message#1531792
>
>No. I can not use from StringToUTF16().
>Is it possible for you to summarize it for me?
local s, utf16
s = chr (227)

if( !StringToUTF16(@m.utf16, m.s, 1256) )
  && problem
endif
*_______________________________________________________________________________
#define CP_ACP					0
#define CP_MACCP				2
#define CP_OEMCP				1
#define CP_SYMBOL				42
#define CP_THREAD_ACP			3
#define CP_UTF7					65000
#define CP_UTF8					65001
#define MB_PRECOMPOSED			0x1
#define MB_COMPOSITE			0x2
#define MB_USEGLYPHCHARS		0x4
#define MB_ERR_INVALID_CHARS	0x8

#define WC_DEFAULTCHAR			0x00000040 
#define WC_ERR_INVALID_CHARS	0x00000080 
#define WC_NO_BEST_FIT_CHARS 	0x00000400 
*_______________________________________________________________________________
function StringToUTF16(utf16Out, stringIn, codepageIn)

	local success
	success = true
	
	do case
	case !m.success
	
	case empty(len(m.stringIn))
		utf16Out = ''
		
	otherwise
		local lpWideCharStr, result
		lpWideCharStr = space(len(m.stringIn)*2)
	
		result = MultiByteToWideChar( ;
					evl(m.codepageIn, cpcurrent()), ;
					MB_ERR_INVALID_CHARS, ;
					@m.stringIn, ;
					len(m.stringIn), ;
					@m.lpWideCharStr, ;
					len(m.lpWideCharStr) ;
				)
			
		do case
		case !m.success
		
		case empty(m.result)
			assert false
			success = false
		
		otherwise
			utf16Out = left(m.lpWideCharStr, m.result * 2) 
		
		endcase
		
	endcase
	
	return m.success
	
	
endfunc
*_______________________________________________________________________________


function MultiByteToWideChar
	lparameters codepage, ;
				dwFlags, ;
				lpMultiByteStr, ;
				cbMultiByte, ;
				lpWideCharStr, ;
				cchWideChar

	local success
	success = true

	local result
	
	do case
	case !m.success
	
	otherwise
		try
			declare integer MultiByteToWideChar in Kernel32.dll ;
				long	codepage, ;
				long	dwFlags, ;
				string@	lpMultiByteStr, ;
				integer	cbMultiByte, ;
				string@	lpWideCharStr, ;
				integer	cchWideChar
		
			result = MultiByteToWideChar( ;
					m.codepage, ;
					m.dwFlags, ;
					@m.lpMultiByteStr, ;
					m.cbMultiByte, ;
					@m.lpWideCharStr, ;
					m.cchWideChar ;
				)
		catch
			assert false
			success = false
			
		endtry
	endcase
	
	return iif(m.success, m.result, 0)
	
endfunc
*_______________________________________________________________________________
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform