Page 1 of 1

Field from a word

Posted: Tue Aug 17, 2010 1:35 pm
by arunkumarmm
My requirement is to split the incoming string based on the no. of words.

If the source data has four words, my output should be C1 - first 2 words and C2 - next 2 words.

If there are 7 words, C1 - 3 words and C2 - next 4 words.

I can count the no. of spaces and div by 2 and find the word from which the string should be split.

As Field fn will not accept more than one char as delimiter, If it is server, I can use the Ereplace and replace that word with @FM and use @FM as delimiter in Field fn to extract first part.

Is there a similar kind of fn in parallel that I can use to achieve this?
I believe convert can only replace single char.

Posted: Tue Aug 17, 2010 1:48 pm
by anbu
Use Field function to extract the words based on the delimiter

Posted: Tue Aug 17, 2010 1:53 pm
by Sainath.Srinivasan
There is an EReplace function available in this forum. Please search and use it.

Posted: Tue Aug 17, 2010 1:59 pm
by arunkumarmm
anbu wrote:Use Field function to extract the words based on the delimiter
Anbu, creating the delimiter is my problem. I cannot replace the entire word with @FM using convert nor I can use that word as delimiter in the field function.

In server I can write the derivation like,

Field(Ereplace('Arun Kumar','Kumar',@FM),@FM,1),
Is there a similar function/way in parallel?

Posted: Tue Aug 17, 2010 2:08 pm
by anbu
If i understand your requirement

Code: Select all

wrds="A B C D"
C1=Field(wrds," ",1) : Field(wrds," ",2)
C2=Field(wrds," ",3) : Field(wrds," ",4)
You can have two links from transformer one constraint as space count equal to 4 and other for 7. In second link write derivation like above to get 3 and 4 words from your input

Posted: Tue Aug 17, 2010 2:14 pm
by arunkumarmm
No Anbu. My requirement is to split the input string into two, if the words are not equal maximum words should be on the second column. No. of words are dynamic in the input.

Eg., Str = "One Two Three Four"
O/P: C1 = 'One Two" C2 = "Three Four"

If Str = "One Two Three Four Five"
O/P: C1 = 'One Two" C2 = "Three Four Five"

If Str = "One Two Three Four Five Six Seven"
O/P: C1 = 'One Two Three" C2 = "Four Five Six Seven"

And no restriction for No. of words in the input. Hope this is clear.

Posted: Tue Aug 17, 2010 2:15 pm
by arunkumarmm
arunkumarmm wrote:
anbu wrote:Use Field function to extract the words based on the delimiter
Anbu, creating the delimiter is my problem. I cannot replace the entire word with @FM using convert nor I can use that word as delimiter in the field function.

In server I can write the derivation like,

Field(Ereplace('Arun Kumar','Kumar',@FM),@FM,1),
Is there a similar function/way in parallel?
Thanks Sainath. I found that.

Posted: Tue Aug 17, 2010 5:10 pm
by ray.wurlod
You don't need Ereplace() to split. Field() function alone will suffice.

Posted: Tue Aug 17, 2010 10:26 pm
by arunkumarmm
Field will work only if the delimiter is one character. If the delimiter is more than one, it will take the first character as delimiter

Posted: Wed Aug 18, 2010 12:07 am
by ray.wurlod
The requirement does not specify multiple-character delimiters.

Posted: Wed Aug 18, 2010 2:11 am
by Sainath.Srinivasan
Wait a sec, I have a different idea.

When you say your delimiter is of more than one character, does it imply 2 identical characters or different values.

For example, do you see
'ThisbbIsbbAbbTestbbString'
Or
'ThisXYIsXYAXYTestXYStringXY'
If it is the first case, you can take fields of odd numbers together or trim your fields before concat. In second case, you can use your first delimiter ('X' in this case') in your field function and remove leading 'Y's from your non-first columns.

These remove the need for EReplace. But includes one extra step.

Posted: Mon Aug 23, 2010 2:37 pm
by arunkumarmm
ray.wurlod wrote:The requirement does not specify multiple-character delimiters. ...
Ray, I quoted that field fn will not accpet more than one char as delimiter.

I'm sorry if that was not clear.
As Field fn will not accept more than one char as delimiter, If it is server, I can use the Ereplace and replace that word with @FM and use @FM as delimiter in Field fn to extract first part.

Is there a similar kind of fn in parallel that I can use to achieve this?
I believe convert can only replace single char.

Posted: Mon Aug 23, 2010 2:49 pm
by arunkumarmm
Sainath.Srinivasan wrote:Wait a sec, I have a different idea.

When you say your delimiter is of more than one character, does it imply 2 identical characters or different values.

For example, do you see
'ThisbbIs ...
Sai, Thanks for your reply!

I dont have any specific delimiter. I want to split the incoming string based on the no. of words. So I want to use one of those words as a delimiter to split it.
Eg.,
If Str = "One Two Three Four Five Six Seven"
O/P should be: C1 = 'One Two Three" C2 = "Four Five Six Seven"

What I'm trying to do is, Count(Str,' ') = 6, 6/2 = 3, so my column 1 should have 3 words. So, so replace the 4th word with @FM, use it as delimiter and extract the first three words.