Page 1 of 1

Transform string fron one code page xxx to ASCII

Posted: Thu Dec 03, 2015 12:09 pm
by Victorio
Hi,
I am looking some function to transform characters from code page Windows 1250 and Latin II (DOS) to ASCII.
I have function with DO CASE... where every characters converted to ASCII code. (chr 001-127)
But it slowing my app.
I saw somewhere function to manipulating with string, to replace characters from one string to other, but I cannot find it.

I have this :

FUNCTION lat_ibm_u(ptext)
LOCAL outriadok:=space(0),pocet:=0,i:=0,znak:=0
pocet:=len(ptext) && zistenie poctu znakov v riadku
for i=1 to pocet
znak:=asc(ptext)
DO CASE
* Š
CASE znak==138
znak:=83
* Ť
CASE znak==141
znak:=84
* Ž
CASE znak==142
znak:=90
etc.
ENDCASE
outriadok+=chr(znak)
next
RETURN outriadok

Re: Transform string fron one code page xxx to ASCII

Posted: Thu Dec 03, 2015 12:44 pm
by Cliff Wiernik
Instead of a case statement, just create a 1 dimensional array with the conversion. Then your code instead of the case statement would be:

// define array of conversions for the asc return values
aCodes[138] := 83
aCodes[141] := 84
aCodes[142] := 90

for i:= 1 to len(fromcode)
nValue := asc(substr(fromcode,i,1))
tocode := tocode+str(aCodes[nValue])
NEXT

Re: Transform string fron one code page xxx to ASCII

Posted: Thu Dec 03, 2015 12:50 pm
by Auge_Ohr
Victorio wrote:I am looking some function to transform characters from code page Windows 1250 and Latin II (DOS) to ASCII.
you can use different Font / Codepage in a Xbase+ Application.
it is possible to use different Font / Codepage in each Column of a Browse.
DbBrowse_chinese_OEM.JPG
DbBrowse_chinese_OEM.JPG (158.39 KiB) Viewed 17410 times

Re: Transform string fron one code page xxx to ASCII

Posted: Fri Dec 04, 2015 3:30 am
by Victorio
thanks,
Jimmy , I want convert characters with codes 128 - 255 to base ascii codes 001 - 127
for remove national character.
for example :

Jakešovi -> Jakesovi
and then Jakesovi -> JAKESOVI with upper()

It is because I am searching in document and program must find all variants if I want search key "JAKESOVI"
(Jakešovi, JAKEŠOVI,Jakesovi, Jakesovi,Jakéšoví,....)

Re: Transform string fron one code page xxx to ASCII

Posted: Fri Dec 04, 2015 3:52 am
by Tom

Code: Select all

FUNCTION Convert(c)
LOCAL aCodeTab := {{138,83},{141,84},{142,90}}, i
FOR i := 1 TO Len(aCodeTab)
  c := StrTran(c,Chr(aCodeTab[i,1]),Chr(aCodeTab[i,2]))
NEXT
RETURN c
Besides, if working with a LOCAL variable, this works:

Code: Select all

FOR i := 1 TO Len(c)
  c[i] := Something(c[i])
NEXT
No "SubStr" or concatenation needed.

Re: Transform string fron one code page xxx to ASCII

Posted: Fri Dec 04, 2015 7:30 am
by skiman
Hi,

Did you check the following? SET LEXICAL ON with the setlexRule()? I think this is a solution for this kind of problem.

Re: Transform string fron one code page xxx to ASCII

Posted: Sun Dec 06, 2015 11:27 am
by Victorio
skiman: yes, this is, what I am searching, (setwildcollation). I saw it, but cannot find again..
Thanks !
And also Jimmy, Cliff and others for inspiration to improve my source.
Victorio