Page 1 of 1

Removing a specific character from string

Posted: Wed Sep 16, 2015 2:48 pm
by devsonali
Hello everybody
I have a string coming in
its like abc def hsk nmps etc

My requirement is to remove any letter 'a' from the words within the string if it appears as the last letter

For example
"abc def abca" should be come "abc def abc"
"abc def' will not change
"abc nko 2090a sksa" becomes "abc nko 2090 sks"
so on and so forth

As you noticed the string can be of varying length including words

I am trying by looping the string ( unsuccessfully ) and wanted to see
if anybody has better,easier way to handle this

Thank you for looking

Posted: Wed Sep 16, 2015 3:36 pm
by devsonali
Update - Somebody suggested (not finding the post anymore ) using a trim function with 'T'
This helps because I can combine it with other logic to perhaps work it out
However , Trim( string,"a","T")
Trim with T option only seems to work for last words(in this case)
so
"abc def abca" becomes "abc def abc" (as expected)
but
"abc nko 2090a sksa" becomes "abc nko 2090a sks"

Thank you for suggestion

Still looking for options to handle that

Posted: Wed Sep 16, 2015 3:43 pm
by rkashyap
Try External Filter Stage with

Code: Select all

Filter sed
Arguements  's/a / /g;s/a$//g'

Posted: Wed Sep 16, 2015 3:55 pm
by devsonali
Thank you Kashyap, will try to implement that

Posted: Wed Sep 16, 2015 4:08 pm
by chulett
What is your source? The previous suggestion assumes a file, I do believe.

Posted: Wed Sep 16, 2015 4:24 pm
by ray.wurlod
You could create a loop in a Transformer stage that loops through the words. Treat the field as a space-delimited string, use Field() function to extract the individual words.

Posted: Wed Sep 16, 2015 5:39 pm
by rkashyap
Loop in a Transformer would probably perform faster than Unix command running in External Filter stage. I believe that External Filter may be able to process data from any source.

Posted: Thu Sep 17, 2015 6:44 am
by devsonali
Thank you for all your inputs , I have tested (more testing in progess ) it by applying space (trailing) and looking for 'a ' and replacing it with ' ' . I will also test using loops and external filter as suggested

Although , for looping , my logic greatly depends on the sequence of stage variables i am using for other transformation - so wanted to know , does a loop variable execute after the stage variables do ?

Posted: Thu Sep 17, 2015 4:34 pm
by ray.wurlod
For each row processed all stage variables are evaluated before the loop is executed.

Posted: Thu Sep 17, 2015 4:55 pm
by chulett
A recent discussion on execution order, including a link to where it is officially documented! :shock:

:wink: