Basic4ppc - Windows Mobile Development  

Go Back   Basic4ppc - Windows Mobile Development > Main Category > Questions & Help Needed
Home Register FAQ Members List Search Today's Posts Mark Forums Read

Questions & Help Needed Post any question regarding Basic4ppc.


I'm want function UTF-8 to ASCII or utf-8 to tis620


Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-05-2008, 07:59 AM
Newbie
 
Join Date: Aug 2008
Posts: 7
Default I'm want function UTF-8 to ASCII or utf-8 to tis620

I'm want function UTF-8 to ASCII or utf-8 to tis620
'm use SQlite insert2db by Thai language. when preview result filed is 'อ่านไม่ออก'
I'm want function for decode it to ASCII
Exemple sample code php ** but i'm connot converse to VB code
function utf8_to_tis620($string) {
$str = $string;
$res = "";
for ($i = 0; $i < strlen($str); $i++) {
if (ord($str[$i]) == 224) {
$unicode = ord($str[$i+2]) & 0x3F;
$unicode |= (ord($str[$i+1]) & 0x3F) << 6;
$unicode |= (ord($str[$i]) & 0x0F) << 12;
$res .= chr($unicode-0x0E00+0xA0);
$i += 2;
} else {
$res .= $str[$i];
}
}
return $res;
}
Reply With Quote
  #2 (permalink)  
Old 08-05-2008, 10:08 AM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,755
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

Thi is a literal translation of that php code. However it will not work with B4ppc because all strings are UTF16 within the .NET environment in which B4ppc runs.
Code:
Sub  string_utf8_to_tis620(string)
	str = string;
	res = ""
	For i = 0 To StrLength(str) - 1 
		If (Asc(SubString(str,i,1)) = 224) Then
			unicode = Asc(SubString(sti+2,1)) Mod 64
			unicode = unicode + (Asc(SubString(str, i+1,1)) Mod 64) * 64 
			unicode  = unicode + (Asc(SubString(str,i,1)) Mod 16) * 4096
			res = res & Chr(unicode-3584+160)
			i = i + 2
		Else 
			res = res + SubString(str,i,1)
		End If
	Next
	Return res
End Sub
If the UTF8 string is available as a byte array within B4ppc then this might work
Code:
Sub  bytes_utf8_to_tis620
	str = string;
	res = ""
	For i = 0 To ArrayLen(bstr()) - 1 
		If (bstr(i) = 224) Then
			unicode = bstr(i+2) Mod 64
			unicode = unicode + bstr(i+1) Mod 64 * 64 
			unicode  = unicode + bstr(i) Mod 16 * 4096
			Msgbox(unicode)
			res = res & Chr(unicode-3584+160)
			i = i + 2
		Else 
			res = res & Chr(bstr(i))
		End If
	Next
	Return res
End Sub
But this begs the question as to why you want some sort of "ASCII" data within a Unicode environment
Reply With Quote
  #3 (permalink)  
Old 08-05-2008, 03:06 PM
Newbie
 
Join Date: Aug 2008
Posts: 7
Default

Thank you very much
and I want convert this function | PHP to VB | thank you
function tis2utf8($tis) {
for( $i=0 ; $i< strlen($tis) ; $i++ ){
$s = substr($tis, $i, 1);
$val = ord($s);
if( $val < 0x80 ){
$utf8 .= $s;
} elseif ( ( 0xA1 <= $val and $val <= 0xDA ) or ( 0xDF <= $val and $val <= 0xFB ) ){
$unicode = 0x0E00 + $val - 0xA0;
$utf8 .= chr( 0xE0 | ($unicode >> 12) );
$utf8 .= chr( 0x80 | (($unicode >> 6) & 0x3F) );
$utf8 .= chr( 0x80 | ($unicode & 0x3F) );
}
}
return $utf8;
}
Reply With Quote
  #4 (permalink)  
Old 08-05-2008, 09:25 PM
agraham's Avatar
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,755
Awards Showcase
Beta Tester Forum Contributer 
Total Awards: 2
Default

You appear to want to do a conversion from a single byte character string in a TIS620 codepage to UTF8. As I pointed out before this doesn't work, or may not even be necessary in a .NET based application which is UTF16. You need to analyse why you think you need this.
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Function Key eillezcas Questions & Help Needed 0 08-27-2008 09:28 PM
Exp() function Bruno Questions & Help Needed 5 06-05-2008 08:03 PM
ascii character problem Gale Johnson Questions & Help Needed 1 05-28-2008 04:59 PM
how to display chinese characters (High-ASCII, double-byte) using sqlite3 dennychuang Questions & Help Needed 5 05-22-2008 05:39 PM
Serial terminal ,send ASCII/HEX alex_up Russian Forum 0 12-15-2007 12:18 PM


All times are GMT. The time now is 01:13 PM.


Powered by vBulletin® Version 3.6.12
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.1.0