View Single Post
  #2 (permalink)  
Old 08-05-2008, 10:08 AM
agraham's Avatar
agraham agraham is offline
Basic4ppc Expert
 
Join Date: Jul 2007
Location: Cheshire, UK
Posts: 1,907
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