View Single Post
Old 07-19-2012, 06:30 AM   #1 (permalink)
New Member
Join Date: Feb 2012
Model: 9160
Carrier: vodacom
Posts: 4
Post Thanks: 0
Thanked 0 Times in 0 Posts
Post How do I replace more than 1 character in blackberry?

Please Login to Remove!


I know how to replace a certain character with another character in a string:

System.out.println(replaceAll("Where are you??", "?", "")
public static String replaceAll(String front, String pattern, String back){

if (front == null)
return "";

StringBuffer sb = new StringBuffer(); //A StringBuffer is created
int idx = -1;
int patIdx = 0;

while ((idx = front.indexOf(pattern, patIdx)) != -1)
sb.append(front.substring(patIdx, idx));
patIdx = idx + pattern.length();

return sb.toString();

This code will replace all ? with an empty space and would print out ("Where are you")

Now what I want to know is how can I replace more than 1 character. In Java I can just use simple regex, but if in blackberry I write something like:

System.out.println(replaceAll("Henry!! Where are you??", "!?", "")

then blackberry doesn't pick it up. So how do I overcome this limitation that blackberry has?
Offline   Reply With Quote