Compare ASCII converted string in C/AL

grouicgrouic Member Posts: 34
Hello,

I'm importing data from a csv file that potentially contains french or spanish characters (éàñ ... etc).
To have the correct character string in Navision, I use the well known ansi2ascii fonction, that works just fine.

However, it seems that there is a problem when comparing a converted string with a string written in C/AL !

for eg :

var_description = 'hello world' (value of the import)

description := ansi2ascii(var_description);
if description = 'hello world" then ... etc

For Navision description and 'hello world' are not the same strings ....

NB : it works if I write this :

if description = ansi2ascii('hello world') then ... etc

Anyone got this problem ?
Do I really need to convert ALL the strings I need to compare in C/AL ?????

Thx for the help

Comments

  • Dave_CintronDave_Cintron Member Posts: 189
    You may need to compare the upper range of character strings you are converting (128-255) because the Navision code page is not exactly the same as the Windows code page. You would compare what's being imported with the result.
    Dave Cintron
    Dynamics West
    http://www.dynamicswest.com
  • ajhvdbajhvdb Member Posts: 672
    I found using ansi2ascii created new problems for me. It looks a bit like yours and haven't found a solution for this yet :(

    Sometimes (Depending on the programs you use later, f.i. Excel) it converts a "space" to a lower value which in Excel is interpreted as an "à" character. Try your code again but now with "HelloWorld" (without the space).
  • grouicgrouic Member Posts: 34
    Hey ajhvdb, you're right. I tested a comparison on strings not containing spaces, and it works.
    I'm continuing my investigation :D
  • SogSog Member Posts: 1,023
    you could replace spaces with the expression "[space]" (or another expression of your choice), convert the string with ansi2ascii and replace your expression again with regular spaces :)
    |Pressing F1 is so much faster than opening your browser|
    |To-Increase|
  • grouicgrouic Member Posts: 34
    OK I solved my problem.

    In the MakeVars function (CUnit ANSI <-> ASCII converter), I just removed the last char of the strings AsciiStr and AnsiStr.
    The both were visually spaces but only the char in the AnsiStr was a "real" space.

    I did not find which ascii char was used as "space" in the AsciiStr (in a unix file it's displayed as "| ").

    I dont know if it's a bug in the CU.
  • ajhvdbajhvdb Member Posts: 672
    Glad you solved it. :)

    Could you test the following:
    > Open csv in Excel
    > Saveas new csv
    > Compare the two csv files or import in NAV

    In the new csv file, I still have the "à" chars but maybe it is only with my Office version
Sign In or Register to comment.