on 02-28-2007 10:16 AM
Hi Group,
I am new to Java,I have one query related on UDF.
I have a Number 1300015394101HM with lenght 15,if last 2 digits alphabit then I need to take only 13 digits value.Can any body suggest how to write this in JAVA
Hi,
create a UDF with a String a argument
String b = a.substring(13,2);
Boolean isAlp = true;
for (int i=0; i<2; i++)
{
if (!((b.charAt(i)>="A") && (b.charAt(i)<="Z")) || ((b.charAt(i)>="a") && (b.charAt(i)<="z")))
isAlp = false;
}
if (isAlp)
return a.substring(0,13);
else
return "criteria not satisfied";
Thanks,
Rajeev Gupta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Henrique,
your suggestion doesnt meet the requirement......see the req again - it is <b>if last 2 digits alphabit then I need to take only 13 digits value</b>....so you dont have to <i>remove all the non-numeric chars in the last two positions of the string</i>
Thanks,
Rajeev Gupta
Message was edited by:
RAJEEV GUPTA
> Hi Henrique,
>
> your suggestion doesnt meet the requirement......see
> the req again - it is <b>if last 2 digits alphabit
> then I need to take only 13 digits value</b>....so
> you dont have to <i>remove all the non-numeric chars
> in the last two positions of the string</i>
>
> Thanks,
> Rajeev Gupta
>
> Message was edited by:
> RAJEEV GUPTA
It depends.
If the sender application sends only numbers and/or letters at the last 2 positions, than that should satisfy. 😃
Regards,
Henrique.
Hi,
Assume String input is your input number string, then:
// If the 14th character or the 15th character of the input string is an alphabet
if (Character.isLetter(input.charAt(13)) || Character.isLetter(input.charAt(14))) {
//Then return only the first 13 characters
return input.substring(0, 13);
}
//Otherwise, the last two characters are not alphabets, then return the original string
return input;
This will work regardless of the case of the letters and does not assume anything about your input value, and it works faster with the direct return in the if statement.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
85 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.