asmith Posted November 16, 2009 Posted November 16, 2009 I have tried to use the Search function which works fine with a single array of numbers. I cannot get it to work with a single array of strings, it always returns -1 Should it work with string arrays? Thank You
AzeoTech Posted November 17, 2009 Posted November 17, 2009 Yes, it works fine with strings. To test it, I did this at the command/alert: global x = {"a", "b", "c"} ? search(x == "b") and it printed 1
asmith Posted November 26, 2009 Author Posted November 26, 2009 Maybe we are running different versions of DAQFactory, I still cant get it to work. I have 5.84 Build 1636 Here's what happens when I try the same thing.... global y = {"a", "b", "c"} ?y {NaN, NaN, NaN} ? search(y == "b") C1097 String operator found when number expected. If I declare the global as a string array (which is what I'm trying to search) such as..... global string df df[0] = 'DAQFactory" df[1] = 'is" df[2] = 'very" df[3] = 'good" ?df {"DAQFactory"", "is"", "very"", "good""} ?search(df=="is") -1 Any ideas? Thanks
AzeoTech Posted November 26, 2009 Posted November 26, 2009 Sorry, typo on my part. I entered global string x = ..., not global x. Global x would create an array of numbers. You also have a typo, which is why it isn't working. When you are defining the various array elements, you open your string with a single quote and then close it with a double quote. The reason DF supports both single and double quotes is to allow you to put one type in a string without escaping: 'he said: "hi"'. DF isn't checking for the closing ' and assumes the end of the line is the close, so, as you can see when you do ? df, there is a " in your string. So, search(df=="is") returns -1, because there is no "is" in the array, but there is "is"" (three characters, the last being ")
asmith Posted November 27, 2009 Author Posted November 27, 2009 Ah Thank You! I had always wondered why the single or double quotes seemed to do similar things, now I know the reason and how to use them. Also got the search to work! Thanks again. Alistair
Recommended Posts
Archived
This topic is now archived and is closed to further replies.