on 11-07-2008 12:09 AM
My requirement is that I need to seperate out all the special characters in a string and take only the numbers.
If phone number contains any brackets or hyphens, they need to be removed to form only the number.
Since my datatype is string type.. I needed to use the string argument for my function.
Please can anyone tell me how do I achieve this?.
I was looking for a for loop to check the charAt every position.. but how do I seperate the chars of a string to form a new one?.
Please advise.
Hi
If you need to do it only for Numbers then use this in UDF
public String removeNonDigits(String text, Container container) {
int length = text.length();
StringBuffer buffer = new StringBuffer(length);
for(int i = 0; i < length; i++) {
char ch = text.charAt(i);
if (Character.isDigit(ch)) {
buffer.append(ch);
}
}
return buffer.toString();
}
Thanks
Gaurav
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Gaurav.
I was trying with Arraylist..and if and else for all the digits from 1 to 9.
But the character.isdigit function did it for me.
Thanks again.
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.