cancel
Showing results for 
Search instead for 
Did you mean: 

susbtring to get value between "StartsWith" and a Delimiter

Former Member
0 Kudos

Hi Gurus,

I have q requirement to get a certain value from a single source field

/IN/SB/ABC123/ --> requirement is to get the value between /IN/SB/ and the last / e.g. ABC123

the problem is this value is not fixed to 6characters only, can be any number of characters,

so if i use substring here I will encounter out of bounds exception

Can i do this using graphical mapping only?

/IN/SB/ and the last / will always be constant (present in the field)

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

if initial start string is fixed, you can use below in the UDF:

return inputStr.substring(7, inputStr.lastIndexOf("/"));

Former Member
0 Kudos

Hi Yogesh,

yes the initial start string is fixed, and also the last "/"

Can you paste here the entire UDF code for it? I have very little background in java..

Former Member
0 Kudos

Above is the only code you need to put in UDF.

Name the input parameter for UDF as inputStr

Former Member
0 Kudos

Thanks to every body that responded

The code provided by Yogesh is the exact fit for my requirement, Thanks Yogesh!

Former Member
0 Kudos

Hi Yogesh,

Wasn't able to spot this immediately, but the code works for single values only.

What do I need to add in the code if the input string has multiple occurrences?

e.g. when i change the UDF to

Execution Type:

All values of a Context

All values of a Queue

Hope for your kind answer

Answers (6)

Answers (6)

Former Member
0 Kudos

solved with UDF having variable begin and end index based on field length of input field

Former Member
0 Kudos

Hi,

This is possible using standard graphical functions only.

You have to use the "replaceString" function twice.

Check the below mapping:

SourceField -


>

Constant [/IN/SB/] -


> replaceString -


>

Constant [] -


> Constant [/] -


> replaceString -


> Target

Constant [] -


>

-Supriya.

Former Member
0 Kudos

followup question:

if the UDF execution type is not Single Values, what do i need to add to the code?

Please refer to above

vuyyurujyothi
Participant
0 Kudos

Here is the code:

String value = "";

AbstractTrace trace = container.getTrace();

StringTokenizer tempStringTokenizer = new StringTokenizer(input[0], "\n");

while (tempStringTokenizer.hasMoreTokens())

{

value = tempStringTokenizer.nextToken();

trace.addInfo (" TRACE ADDED" );

result.addValue(value);

}

//take udf as queue and mention one input parameter - name as 'input'

//give the source field as input to this udf

//after this udf use splitByValue node function...

vuyyurujyothi
Participant
0 Kudos

Instead of "\n" just use "\" ... sorry forget to change

Former Member
0 Kudos

Hi,

StringTokenizer won't fit the requirement because it breaks down the values in between the delimiter "/"

since /IN/SB/ is constant, and i need the value between it and the last delimiter "/"

Former Member
0 Kudos

Could you please let me know e.g. input and output you are expecting.

justin_santhanam
Active Contributor
0 Kudos

You can use StringTokenizer to achieve this (UDF).

raj.

Former Member
0 Kudos

Hi,

Use this UDF:

String delimiter ="/" ;

String[] temp = var1[0].split(delimiter);

result.addValue(temp[2]);

Note: This UDF will fetch the value after 3 "/" (slash delimiter).

Thanks

Amit Srivastava

Former Member
0 Kudos

Using startsWith is OK. But in place of substring write a UDF.

Edit : On second thoughts why not do the whole thing in a simple UDF. Java understands the method "startsWith"