Transform string fron one code page xxx to ASCII

Xbase++ 2.0 Build 554 or later
Post Reply
Message
Author
Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Transform string fron one code page xxx to ASCII

#1 Post 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

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Transform string fron one code page xxx to ASCII

#2 Post 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

User avatar
Auge_Ohr
Posts: 1422
Joined: Wed Feb 24, 2010 3:44 pm

Re: Transform string fron one code page xxx to ASCII

#3 Post 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 17411 times
greetings by OHR
Jimmy

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Transform string fron one code page xxx to ASCII

#4 Post 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í,....)

User avatar
Tom
Posts: 1205
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Transform string fron one code page xxx to ASCII

#5 Post 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.
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

skiman
Posts: 1195
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Transform string fron one code page xxx to ASCII

#6 Post 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.
Best regards,

Chris.
www.aboservice.be

Victorio
Posts: 633
Joined: Sun Jan 18, 2015 11:43 am
Location: Slovakia

Re: Transform string fron one code page xxx to ASCII

#7 Post 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

Post Reply