Char Value Contains Value

RD_Man

Member
Happy Friday,

In progress I want to check if a column contains a specific value. Example: '12345-A-001', '23146-P-006', '23-9-P'.

I want to find any record with '-P' in it anywhere. I searched "contains" with no luck (previous experience operator).

Thanks,

Mike
 
If the separators are always going to be '-' then you can try

IF LOOKUP("P",lvList,"-") GT 0 THEN
/*We have a P*/
ELSE
/*We don't have a P*/
 
Or, if your list doesn't have guaranteed delimiters, use the INDEX function:

Code:
DEFINE VARIABLE cString AS CHARACTER   NO-UNDO.
 
cString = "23146-P-006".
 
MESSAGE INDEX(cString,"-p")
    VIEW-AS ALERT-BOX INFO BUTTONS OK.
 
Thanks to both of you.

Both options work and have merit in different applications for me.

Have a great weekend!
 
Happy Friday,

In progress I want to check if a column contains a specific value. Example: '12345-A-001', '23146-P-006', '23-9-P'.

I want to find any record with '-P' in it anywhere. I searched "contains" with no luck (previous experience operator).

Thanks,

Mike

The operator you were looking for is "matches".

so, a third option might be:

def var cvalue as char no-undo.

cvalue = "-p-althe".

if cvalue matches string("*-p*") then message "yeah baby".
else quit.
 
Just don't expect it to be fast for anything more than fairly trivial amounts of data.

If you were to, for instance, try something like:

Code:
for each customer no-lock where name matches "*-p*":
  /* do something interesting with customers... */
end.

And if you had, say, a million customer records that query is going to take a very, very long time to run.
 
Tom,

Thanks for the follow up. I will note the speed issue. For my immediate need, I am finding my data via indexes for speed but once found I needed to categorize the data based on the (-?) values.

Mike
 
Back
Top