BlackBerry Forums Support Community

BlackBerry Forums Support Community (http://www.blackberryforums.com/index.php)
-   Developer Forum (http://www.blackberryforums.com/forumdisplay.php?f=15)
-   -   How do I replace more than 1 character in blackberry? (http://www.blackberryforums.com/showthread.php?t=260607)

Lukaszz 07-19-2012 06:30 AM

How do I replace more than 1 character in blackberry?
 
Hi,

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));
sb.append(back);
patIdx = idx + pattern.length();
}

sb.append(front.substring(patIdx));
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?

Dougsg38p 07-23-2012 01:11 PM

Re: How do I replace more than 1 character in blackberry?
 
You will probably have to invent this by using StringMatch and then replacing the data matched.


All times are GMT -5. The time now is 09:47 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.