viewpoint-particle

Author Topic: How to Control ArrayFileGetCSV Data Typing  (Read 1744 times)

1topgun

  • Newbie
  • *
  • Posts: 3
How to Control ArrayFileGetCSV Data Typing
« 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

td

  • Tech Support
  • *****
  • Posts: 2516
    • WinBatch
Re: How to Control ArrayFileGetCSV Data Typing
« Reply #1 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.
"Success is a lousy teacher. It seduces smart people into thinking they can't lose."
  - Bill Gates


DAG_P6

  • Full Member
  • ***
  • Posts: 184
  • WinBatch rocks, and so does Wilson WindowWare!
    • WizardWrx
Re: How to Control ArrayFileGetCSV Data Typing
« Reply #2 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.
David A. Gray
You are more important than any technology.