on 09-04-2015 5:31 PM
Hi Experts,
I need to create UDF to allow only value with A-Z, a-z, 0-9, !@#$% & (),.<>;:’”[]{}-+=\ for all other characters i need to replace with empty string.
Please help on creation of UDF for this requirement.
Thanks in advance.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
Try the below java code in UDF
//Note:- str variable is UDF input
char[] bufferStr = str.toCharArray();
String otherChars = "!@#$%&(),.<>;:\'\"[]{}-+=\\";
char[] bufferOtherChars = otherChars.toCharArray();
StringBuffer sb = new StringBuffer();
for(int i = 0; i < bufferStr.length; i++)
{
if((bufferStr[i] >= 'A' && bufferStr[i] <= 'Z') || (bufferStr[i] >= 'a' && bufferStr[i] <= 'z') || (bufferStr[i] >= '0' && bufferStr[i] <= '9'))
{
sb.append(bufferStr[i]);
}else
{
for (int j = 0; j < bufferOtherChars.length ; j++ )
{
if(bufferStr[i] == bufferOtherChars[j])
{
sb.append(bufferStr[i]);
break;
}
}
}
}
return sb.toString();
Br,
Praveen
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 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.