Compare ASCII converted string in C/AL

grouic
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
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
0
Comments
-
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.0
-
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).0 -
Hey ajhvdb, you're right. I tested a comparison on strings not containing spaces, and it works.
I'm continuing my investigation0 -
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 spaces0
-
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.0 -
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 version0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions