Find prepositions in a string

Post questions here relative to DataStage Enterprise/PX Edition for such areas as Parallel job design, Parallel datasets, BuildOps, Wrappers, etc.

Moderators: chulett, rschirm, roy

Post Reply
hitmanthesilentassasin
Participant
Posts: 150
Joined: Tue Mar 13, 2007 1:17 am

Find prepositions in a string

Post by hitmanthesilentassasin »

Hi,

I was working on finding all prepositions in a string. I have tried the index method but it doesnt work when there are multiple words in the string. So here is what I am trying to achieve.

Code: Select all

source string
1. " I want to know the code"
2. "tobey"
Expected Results: I want to select the first record because it has the word "to" in it. Similarly I would want to identify rows with other prepositions like if, for, to, from etc. Although the second string has got the substring "to" in it, I wouldn't want to select that.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

The trick to avoiding substring matches is to use delimiters, in this case a space. Add one on each end of the full string and each search term:

Search for " to " within " " : source_string : " "
-craig

"You can never have too many knives" -- Logan Nine Fingers
hitmanthesilentassasin
Participant
Posts: 150
Joined: Tue Mar 13, 2007 1:17 am

Post by hitmanthesilentassasin »

Thanks Craig!!

The source string is not restricted to one word which is causing me the trouble. there are multiple words coming from the source and I have a list of preposition words that I need to identify. Is there any other technique that I can apply here?
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

Nothing I posted restricts the source string to only a single word. What kind of trouble are you having? Can you post some examples?
-craig

"You can never have too many knives" -- Logan Nine Fingers
hitmanthesilentassasin
Participant
Posts: 150
Joined: Tue Mar 13, 2007 1:17 am

Post by hitmanthesilentassasin »

Below is the function I have defined

Code: Select all

index('| of | in | to |', '| ' : sourcecolumn : ' |',1 )
with the above function I am getting a match when the source column is having a single word like "IF" or "TO" but it wouldn't match it when the word is in between a string like "I want to enjoy Christmas"
ray.wurlod
Participant
Posts: 54607
Joined: Wed Oct 23, 2002 10:52 pm
Location: Sydney, Australia
Contact:

Post by ray.wurlod »

Can't be done this way. You have to search for each preposition separately. Use Transformer stage looping.
IBM Software Services Group
Any contribution to this forum is my own opinion and does not necessarily reflect any position that IBM may hold.
chulett
Charter Member
Charter Member
Posts: 43085
Joined: Tue Nov 12, 2002 4:34 pm
Location: Denver, CO

Post by chulett »

And don't use pipes unless your values are pipe delimited in your source string. In other words, match what is existing in both what you tack on each end of the source string and what you wrap each word with. Your example showed spaces, hence my posted example. And then as Ray noted, you need to do each word separately. If you don't want to go looping, set up a stage variable for each.
-craig

"You can never have too many knives" -- Logan Nine Fingers
Post Reply