cancel
Showing results for 
Search instead for 
Did you mean: 

Substring

Former Member
0 Kudos

Hi,

In the mapping I am working on the requiorement is like this

Source:HeaderComment1

Target:4440

If the value for HeaderComment1 exists in the input payloadd,then the first 35 characters of the HeaderComment1 should be mapped to the target field 4440.

But the input can consist of less than 35 characters as well.

So,if I use the Substring function with range as 0 to 35 then an exception occures.

Please help me on this.

Thanks in advance

Accepted Solutions (1)

Accepted Solutions (1)

former_member472138
Active Contributor
0 Kudos

What if it is more than 35?

baskar_gopalakrishnan2
Active Contributor
0 Kudos

>What if it is more than 35?

The else block will execute and you get string of first 34 chars

Answers (6)

Answers (6)

Former Member
0 Kudos

answered

Former Member
0 Kudos

Hi,

Create a User Function Definitions with the code below:

if (value.length ()> 35) {

return value.substring (0,35);

}

return value;

This will solve your problem.

Edited by: Marlon Sperandio Monteiro on May 25, 2011 10:21 PM

Former Member
0 Kudos

chk this also ...

input will be "a"

execution type: single value..



if(a ! =null)
{
if(a.length()<34)
{
return a;
}
else{
return(a.substring(0,34));
} 
}

rajasekhar_reddy14
Active Contributor
0 Kudos

Write Logic like below

Check first HeaderComment1 exists in input paly load or nout use exists function, then check lenghth of HeaderComment1

if length leass then 35 then substring(0)done specifiy end postion else substring(35,0).

it is very simple,

Regards,

Raj

Former Member
0 Kudos

Hi Raja Sekhar,

For all the characters less than 35,we can map count as 0 to 0 in the substiring funstion,is it?

Please help me.

Thanks in advance

Former Member
0 Kudos

Hi.

I think below should work for u in graphical mapping itself.

headerComment1>exists>Ifwithoutelse

1. then

if > HeaderComment1>length>greaterthan>35>then substring(0,35)>4440

else >Headercomment1>4440

Thanks

Kiran.

rajasekhar_reddy14
Active Contributor
0 Kudos

>

> For all the characters less than 35,we can map count as 0 to 0 in the substiring funstion,is it?

>

Mention start postion 0,and count 0.

You dont required UDF ,using standard function Substring and length, greaterthan and if with else can be achived very easilty.

Former Member
0 Kudos

I agree with Raja.

former_member472138
Active Contributor
0 Kudos

String s = 'abcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmnopqrstuvwxyz01234567890123456789'

String x;

for( int i = 0; i <=34; i++)

{

x<i>=s<i>;

}

return x;

Regards

Pothana

Edited by: Pothana Yadav on May 25, 2011 12:09 PM

Edited by: Pothana Yadav on May 25, 2011 12:09 PM

Former Member
0 Kudos

Try with this:

String input =  'abcdefghijklmnopqrstuvwxyz01234567890123456789abcdefghijklmnopqrstuvwxyz01234567890123456789';
String output;
int lenght;

lenght = Integer.parseInt(input.length());

If ( lenght < 34 )
output = input.substring(0,lenght);
else
output = input.substring(0,34);


return output;

Former Member
0 Kudos

Hi Pothana,

Thanks for the quick reply.

The condition is that there can be more than 35 characters,but if

1.the count is greater than 35,then first 35 characters should be mapped

2.the count is less than 35 then all the characters should be mapped.

I am implementing the code you provided but not getting what variables to declare

I have declared

String X.

Execution Type:All values of a context

but still I am getting an error.

Do I need to declare some other variables also?

Please help me

Thanks in advance

Former Member
0 Kudos

Hello Shweta,

Try with my code write above.

Variable <input> must be declared like input parameter in UDF, <output> must be declared like output parameter (then, delete from code this declaration)

former_member472138
Active Contributor
0 Kudos

Follow strictly

1. Create function from Mapping editor

2. Provide Name: LimitedValue

3. Title: Capture up to 35 chars

4. Execution Type: Single Values

5. Category: User-Defined

6. Argument: InputOne

7. Click on Create Function

8. Juss write these code

if (varOne.length()> 35) {

return varOne.substring (0,35);

}

return varOne;

9. Close and Map this UDF with your source and target fields.

10. Test it.

Bye.

former_member472138
Active Contributor
0 Kudos

Follow strictly

1. Create function from Mapping editor

2. Provide Name: LimitedValue

3. Title: Capture up to 35 chars

4. Execution Type: Single Values

5. Category: User-Defined

6. Argument: InputOne

7. Click on Create Function

8. Juss write these code

if (varOne.length()> 35) {

return varOne.substring (0,35);

}

return varOne;

9. Close and Map this UDF with your source and target fields.

10. Test it.

Bye.

Former Member
0 Kudos

Hi

You can append 35 spaces to HeaderComment1 (through concat function), then use substring and trim to remove spaces.

Regards,

Giuseppe