BlackBerry Forums Support Community               

Closed Thread
 
LinkBack Thread Tools
Old 10-16-2009, 06:07 AM   #1 (permalink)
New Member
 
Join Date: Sep 2009
Model: 7100t
PIN: N/A
Carrier: o2
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default String replace

Please Login to Remove!

Hi,

I am trying to do something simple, however seem to be struggling on how to do this with the blackberry.

I have a string, I want to replace part of it with something else, however the only option seems to be replace char. Which for me is useless.

String str = "some words"

str.Replace("words","crisps");

However this is invalid as not a char.
Offline  
Old 10-16-2009, 07:00 AM   #2 (permalink)
New Member
 
Join Date: Oct 2009
Model: 8900
PIN: N/A
Carrier: Vodaphone
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

try this

Code:
String str = "some words";

        str = str.replace("words","crisps");
        
        System.out.println(str);
Offline  
Old 10-16-2009, 08:15 AM   #3 (permalink)
New Member
 
Join Date: Sep 2009
Model: 7100t
PIN: N/A
Carrier: o2
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for the reply, however I get the following error

replace(char,char) in java.lang.String cannot be applied to (java.lang.String,java.lang.String)
Offline  
Old 10-16-2009, 08:50 AM   #4 (permalink)
New Member
 
Join Date: Oct 2009
Model: 8900
PIN: N/A
Carrier: Vodaphone
Posts: 11
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

well that a bit annoying sorry i was presuming that it would work as standard java.
That means your going to have to do some dodgy loop function to go through your string i.e...

Code:
 String str = "some words";

                int getIndex = str.indexOf("words");
                
                String tempFirstStr;
                String tempSecondStr;
                String tempStr = "";
                
                if(getIndex >= 0)
                {
                    if(getIndex >0)
                    {
                        tempStr = str.substring(0,getIndex);
                        tempStr += " crisps ";
                        tempStr += str.substring((getIndex + 5),str.length());
                    }
                    else
                    {
                        tempStr =  " crisps "+ str.substring((getIndex + 5),str.length());
                    }
                }
obviously this is simplistic as per your example youll probably have to come up with something a bit more complex.
Offline  
Old 10-16-2009, 09:31 AM   #5 (permalink)
New Member
 
Join Date: Sep 2009
Model: 7100t
PIN: N/A
Carrier: o2
Posts: 5
Post Thanks: 0
Thanked 0 Times in 0 Posts
Default

cheers for that, will give it a go.
Offline  
Closed Thread


Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

5Pcs Dip-32 W29c020c-90B W29c020c W29c020 256K X8 Cmos Flash Memory New Ic J
$6.32
5Pcs Dip-32 W29c020c-90B W29c020c W29c020 256K X8 Cmos Flash Memory New Ic J pictureCrucial 32GB Kit (16GBx2) DDR3L 1600 MT/s (PC3L-12800) SODIMM Memory
$383.24
Crucial 32GB Kit (16GBx2) DDR3L 1600 MT/s (PC3L-12800) SODIMM Memory  pictureCrucial 16GB Single DDR3L 1600 MT/s (PC3L-12800) SODIMM Memory CT204864BF160B
$209.99
Crucial 16GB Single DDR3L 1600 MT/s (PC3L-12800) SODIMM Memory CT204864BF160B pictureCrucial 16GB Kit (8GBx2) DDR3 SODIMM Notebook Memory Modules with Crucial MX300
$339.99
Crucial 16GB Kit (8GBx2) DDR3 SODIMM Notebook Memory Modules with Crucial MX300  pictureCrucial 8GB Kit (4GBx2) DDR3L 1600 MT/s (PC3L-12800) SODIMM 204-Pin Memory
$72.99
Crucial 8GB Kit (4GBx2) DDR3L 1600 MT/s (PC3L-12800) SODIMM 204-Pin Memory picture






Copyright 2004-2016 BlackBerryForums.com.
The names RIM and BlackBerry are registered Trademarks of BlackBerry Inc.