How to Control ArrayFileGetCSV Data Typing

Started by 1topgun, June 04, 2015, 02:28:34 PM

Previous topic - Next topic

1topgun

I'm loading a CSV file into an array using ArrayFileGetCSV, then using ArraySearch to look values from the resulting array.

It works fine when the ArraySearch target column contains alpha characters, but when it contains strings that resemble numeric values I get unexpected results - a search for 1.20 returns a match to 1.2

The lookup column has values like 1.1, 1.2, 1.3 .. 99.99, and I'm seeing the same pattern with 1.10 matching 1.1, 2.10 matching 2.1 etc. The problems seems to be that ArrayFileGetCSV creates NUMERIC data types for fields that look like numbers - although my data represents character strings where 1.1 is distinct from 1.10 (where they are numerically equal)

Question: Is there any way to control either the data types for the array elements populated by ArrayFileGetCSV?

Thanks,

Rick

td

Your problem isn't the result of ArrayFileGetCsv treating text as numbers.  It is ArraySearch treating text as numbers.  There are several ways around this but if you happen to have the latest version of WinBatch sorting your array might be the best solution.  For example, you can force ArraySearch to treat all a values as text by first sorting your array using either the @Stringsort or @Logicalsort sort option on the targeted column .  You can then search the array on the sort column using the same @Stringsort or @Logicalsort sort option with ArraySearch.
"No one who sees a peregrine falcon fly can ever forget the beauty and thrill of that flight."
  - Dr. Tom Cade

DAG_P6

Another benefit of sorting before searching is that the sorted array can be searched on that column by the very efficient Binary Search algorithm. However, from a performance perspective, a one-off search probably doesn't gain much; I suspect the cost exceeds the benefit until the fourth or fifth search of the same data.
David A. Gray
You are more important than any technology.