Page 1 of 1

Function to find string

Posted: Thu May 05, 2005 4:26 pm
by kab123
Hi,

What function can I use to find a string in a field..The specific string may be anywhere in the whole field.. I am trying to find the string..If it is found, I have to do something If not something else.

Thanks

Posted: Thu May 05, 2005 4:42 pm
by ds_developer
You could use the INDEX function.
John

Function to find string

Posted: Thu May 05, 2005 4:58 pm
by Sunshine2323
You can also try the COMPARE function :)

Posted: Thu May 05, 2005 5:03 pm
by kab123
Can we use Index function even If we dont know where exactly the string in the field is ..?

ex: I am looking for a string 'CARE' in "THE HEART CARE CENTER INC"

Thanks

Posted: Thu May 05, 2005 8:22 pm
by kduke
index() will tell you where in the string it exists.

Posted: Thu May 05, 2005 11:22 pm
by ray.wurlod
INDEX(string, search_string, occurrence)
  • INDEX("I had to edit it", "it", 1) finds the first occurrence of "it" in the original string (at character position 12) and returns 12.

    INDEX("I had to edit it", "it", 2) finds the second occurrence of "it" in the original string (at character position 15) and returns 15.

    INDEX("I had to edit it", "it", 3) searches for the third occurrence of "it" in the original string, fails to find it, and returns 0.
Because DataStage BASIC has the rule 0 is "false" and another value is "true", the result of INDEX can be used in a Boolean context.

Code: Select all

If Index("ABC", A, 2) Then "at least two A characters" Else "less than two A characters"

Posted: Fri May 06, 2005 8:13 am
by kab123
Thanks Kim and Ray...
I was littlebit curious, if a specific function exists that can find a substring anywhere in the whole field and if found, I need to concatenate 4 other fields...
but I can use Index() in a stage variable and work it out..

Thanks again...

Posted: Fri May 06, 2005 9:58 am
by Sainath.Srinivasan
Can you elaborate on your requirement. I believe that others have answered your question as per the information provided by you.

Posted: Fri May 06, 2005 11:16 am
by kab123
Sai,

I have to look for some set (around 40) of words/strings like "REHAB" and so on in a field of 50 bytes.. If I find these strings "REHAB" some where in the field, Then I have to map some thing in field1, field2, filed3, field4..If I dont find any of those set of words, i need to map some other thing in field1, field2, filed3, field4..

i am thinking to use the Index function in Stage Var and map accordingly..anymore suggestions..welcome !! :)

Thanks

Posted: Fri May 06, 2005 2:01 pm
by leomauer
There is also Count function:
Count (string, substring)
Returns count or null

Posted: Sat May 07, 2005 5:49 am
by ray.wurlod
Nope. Count() function returns actual count (of occurrences of substring in main string, without overlap), whether zero or larger.