Search with arrays containing strings


asmith

Recommended Posts

Posted

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

  • 2 weeks later...
Posted

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

Posted

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 ")

Posted

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

Archived

This topic is now archived and is closed to further replies.