cancel
Showing results for 
Search instead for 
Did you mean: 

Spliting source string

Former Member
0 Kudos

Message mapping my source string having 150 Char but I want to break up 20 Char 20 char put in the target mgs .

We need write UDF or we can do any other way

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Thanks for given answers

Answers (5)

Answers (5)

0 Kudos

Hi Chandra,

Please find the logic below.


Mapping screen


UDF Elements


Count Parameter

In the code, Count is used as constant which specifies the length of each string that should be split from the Input String. This can be passed as normal constant or parameter. In your case, it should be 3.

The parameter can be varied based on the requirement.

Length Condition Handled

If the input string can't be split up into equal sub strings, [For e.g AAABBBC(length7) is to be split into strings of length 3] we are padding tilde symbol at last of source string for initial splitting and finally removing the same while posting to the target.


UDF Code

int len = Inp[0].length();

int Mod = len % Count[0];

if( Mod != 0)

{

Inp[0] = String.format("%0$-" +(len+Count[0]-Mod)+ "s", Inp[0]).replace(' ','~');

}

String out;

for(int i=0;i<len;i=i+Count[0])

{

out = Inp[0].substring(i,Count[0]+i);

if( i == len-Mod)

{

out = out.replace("~","");

}

Res.addValue(out);

}


Mapping Test 1 [Count -3]


Mapping Test 2 [Count -3]


Mapping Test 3 [Count -4]

Could you please let us know if this is helpful.

Regards

Baski

0 Kudos

Hi Chandra,

You mean to say target is one field with occurrence, 0..unbounded ?

Regards

Baski

iaki_vila
Active Contributor
0 Kudos
Former Member
0 Kudos

Source field

AAABBBCCCDDD…….YYYZZZ

Target filed

I want break up 3 , 3 ,3 char like

Field1AAA

Field2BBB

Field3CCC

Field4DDD

.

.

FieldNZZZ

I think Countable Char means we can use substring,, If we get more char What we have to do?

Former Member
0 Kudos

Can you please give example of source and target message.