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

AC 260V 10A Digital Voltmeter Ammeter Current Power Energy Meter Detector LCD
$12.89
AC 260V 10A Digital Voltmeter Ammeter Current  Power Energy Meter Detector LCD  pictureAC 260V 100A Digital Voltmeter Ammeter Power Energy Meter STN Blue LCD Backligh
$14.12
AC 260V 100A Digital Voltmeter Ammeter Power Energy Meter STN Blue LCD Backligh pictureDROK Small Digital Ammeter Amp Gauge Amperemeter 0.56" 100A DC Electric Meter...
$16.86
DROK Small Digital Ammeter Amp Gauge Amperemeter 0.5610pcs Voltage Ammeter Shell 3Bit 0.56 Digital Tube Case Plastic Shell
$8.29
10pcs Voltage Ammeter Shell 3Bit 0.56 Digital Tube Case Plastic Shell pictureHOT DC 100V 10A Voltmeter Ammeter Blue+Red LED Dual Volt Amp Meter Gauge #AL
$1.39
HOT DC 100V 10A Voltmeter Ammeter Blue+Red LED Dual Volt Amp Meter Gauge #AL picture






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