cancel
Showing results for 
Search instead for 
Did you mean: 

Variable length in substring

Former Member
0 Kudos

i am trying unsuccessfully to write a udf, as suddenly the fixed length field i was using a substring on has changed to a variable length field...

i need to pass the field into a UDF and then pass out the last two characters for one field...

and the last 5 for another field.

once i have the UDF working for one, i can amend it for the other...

i am probably a million miles away from the solution... but this is where i am so far...

can someone guide me as to how i can pass the variable length into the substring parameter??


String str = var1;
int length = str.length();

output(var1.substring(length -2))

}

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

just one line:

return var1.substring(var1.length()-2);

What should "output" do in your example?

Former Member
0 Kudos

the output was supposed to be the answer....

i was trying to learn from the Java guides... and then combine two solutions....

but thank you,... an elegant solution! 🐵

Answers (1)

Answers (1)

Shabarish_Nair
Active Contributor
0 Kudos

try;

int length = input.length();
String out = input.substring(length-2,length);
return out;