WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: 1topgun on June 04, 2015, 02:28:34 PM

Title: How to Control ArrayFileGetCSV Data Typing
Post by: 1topgun on June 04, 2015, 02:28:34 PM
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
Title: Re: How to Control ArrayFileGetCSV Data Typing
Post by: td on June 04, 2015, 03:14:35 PM
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.
Title: Re: How to Control ArrayFileGetCSV Data Typing
Post by: DAG_P6 on June 19, 2015, 12:00:59 PM
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.