string tokenize

Hi,

I have requirement for checking the pipe (|) and removing the third string

like incoming string would be GB|0923774|385763 and I have to return out GB|0923774. If input is GB|0923377 then no need to take any action.

Please let me know how to implement logic.

Thanks and Regards,
Akshay

Akshay,

There are more than one ways to do this, but before I jump into explaining, can you confirm that your string can have max 2 occurrences of | and you have to get rid of the string after second | or can there be multiple occurrences of pipe and you have to get rid of every third string?

eg can your string be: GB|0923774|385763|GB|4523223|7873234
and desired output is: GB|0923774|GB|4523223

or will it always be only like: GB|0923774|385763 requiring output to be
GB|0923774?

Obviously the latter is much simpler to achieve.

~ Rohit

Hi Rohit,

yes my string always contain max 2 pipe.

My input string always will be like GB|0923774|385763 or GB|0923774 and required output for both condition should be GB|0923774.

Akshay

Review the descriptions for these services.

pub.string:tokenize
pub.string:makeString

You should be able to do this with just these two calls and a map step or two.

Akshay,

Using with string:tokenize(input yourstring,delim= | returns ValueList),using map steps you can use valuelist[0,1] indexes or loop it and append them to a newstringlist and finally use string:makeString(input newstringlist,delim = |) to form GB|0923774

This logic should work with both of your cases when input is GB|0923774|385763 or GB|0923774…

Sorry Rob,i didnt see your post before my post which has similar suggestion and later realized.

HTH,
RMG

There you have your answer Akshay - tokenize and then makeString. When mapping from valueList (result of tokenize) to makeString’s element array, set proper indices under the properties.

~ Rohit

Thanks all it’s works !!! nice to see I registered on good active forum and all credit goes to u.

Hi.
I’d like to ask, how can I get stringList with three values from this one: 0035;;23 ??
I need to get three values second should be $null, or ’ '.
Thx.

Write a Java service that has the same service signature as pub.string:tokenize but name it something like myutils.string:split (put it into whichever folder makes most sense for your general purpose utilities).

Within the service, use String.split to perform the work (requires JVM 1.4 or later).