cancel
Showing results for 
Search instead for 
Did you mean: 

Simple UDF question.

Former Member
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

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

Answers (1)

Answers (1)

Former Member
0 Kudos

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.