Function to find string

Post questions here relative to DataStage Server Edition for such areas as Server job design, DS Basic, Routines, Job Sequences, etc.

Moderators: chulett, rschirm, roy

Post Reply
kab123
Participant
Posts: 92
Joined: Tue May 18, 2004 4:05 pm

Function to find string

Post 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
ds_developer
Premium Member
Premium Member
Posts: 224
Joined: Tue Sep 24, 2002 7:32 am
Location: Denver, CO USA

Post by ds_developer »

You could use the INDEX function.
John
Sunshine2323
Charter Member
Charter Member
Posts: 130
Joined: Mon Sep 06, 2004 3:05 am
Location: Dubai,UAE

Function to find string

Post by Sunshine2323 »

You can also try the COMPARE function :)
Warm Regards,
Amruta Bandekar

<b>If A equals success, then the formula is: A = X + Y + Z, X is work. Y is play. Z is keep your mouth shut. </b>
--Albert Einstein
kab123
Participant
Posts: 92
Joined: Tue May 18, 2004 4:05 pm

Post 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
kduke
Charter Member
Charter Member
Posts: 5227
Joined: Thu May 29, 2003 9:47 am
Location: Dallas, TX
Contact:

Post by kduke »

index() will tell you where in the string it exists.
Mamu Kim
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post 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"
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
kab123
Participant
Posts: 92
Joined: Tue May 18, 2004 4:05 pm

Post 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...
Sainath.Srinivasan
Participant
Posts: 3337
Joined: Mon Jan 17, 2005 4:49 am
Location: United Kingdom

Post by Sainath.Srinivasan »

Can you elaborate on your requirement. I believe that others have answered your question as per the information provided by you.
kab123
Participant
Posts: 92
Joined: Tue May 18, 2004 4:05 pm

Post 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
leomauer
Premium Member
Premium Member
Posts: 100
Joined: Mon Nov 03, 2003 1:33 pm

Post by leomauer »

There is also Count function:
Count (string, substring)
Returns count or null
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Nope. Count() function returns actual count (of occurrences of substring in main string, without overlap), whether zero or larger.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
Post Reply