cancel
Showing results for 
Search instead for 
Did you mean: 

String into many segments

Former Member
0 Kudos

Hi.

I get a string in a field that I want to covert into many segments with a field containing parts of the string.

Here's an example of a string.

S1265159S1265165S32007S32009S00612

This string should create an segment for each S part

The result should be

<segment>
   <field>S1265159<field/>
<segment/>
<segment>
   <field>S1265165<field/>
<segment/>
<segment>
   <field>S32007<field/>
<segment/>
<segment>
   <field>S32009<field/>
<segment/>
<segment>
   <field>S00612<field/>
<segment/>

I've mapped the incoming field to the segment and to the field with an UDF that looks as follow.

public void StringToSnote(String[] a,ResultList result,Container container){
String[] results = a[0].split("S");
String outdata = "";
for (int i=0; i<results.length; i++) {
	if(results<i>.length()>0)
	{
		if(results<i>.length()>8)
		{
			outdata = "S"+results<i>;
			outdata = outdata.substring(0,8);
		}
		else
		{
			outdata = "S"+results<i>;
		}
		result.addValue(outdata);
		result.addValue(ResultList.CC);
	}
         }
}

It only creates the first segment.

The qeues looks ok according to me and the correct number of segments should have been created.

What have I missed?

BR

Kalle

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

you need a similar function to map it to segment also.

segemnt queue needs as many entries as field, but no CC

Former Member
0 Kudos

I use the function for both segmetn and the field.

BR

Kalle

stefan_grube
Active Contributor
0 Kudos

You cannot use the same function for both fields, as segment queue must not have context change

stefan_grube
Active Contributor
0 Kudos

What you can do: remove result.addValue(ResultList.CC); in your code and map like this:

UDF - segment

UDF - splitbyvalue - field.

Your UDF creates a CC too much, so using splitbyvalue outside is the better aproach anyway.

Former Member
0 Kudos

Hi,

create 2 udf's:

UDF1:

String delimiter ="S" ;

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

for(int i=0;i<temp.length;i++)

{

if(temp<i>.length()>0)

{

result.addValue("");

}

}

UDF2:

String delimiter ="S" ;

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

for(int i=0;i<temp.length;i++)

{

if(temp<i>.length()>0)

{

String a = "S" + temp<i>;

result.addValue(a);

result.addValue(ResultList.CC);

}

}

Mapping:

Source-> UDF1->Segment

Source -> UDF2-> filed

Thanks

Amit

Former Member
0 Kudos

I removed the line you mentioned Stefan.

Split by value was not needed.

BR

Kalle

Answers (0)