BlackBerry Forums Support Community
              

Closed Thread
 
Thread Tools
Old 10-16-2009, 06:07 AM   #1
mabin
New Member
 
Join Date: Sep 2009
Model: 7100t
PIN: N/A
Carrier: o2
Posts: 5
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
kharnmcd
New Member
 
Join Date: Oct 2009
Model: 8900
PIN: N/A
Carrier: Vodaphone
Posts: 11
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
mabin
New Member
 
Join Date: Sep 2009
Model: 7100t
PIN: N/A
Carrier: o2
Posts: 5
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
kharnmcd
New Member
 
Join Date: Oct 2009
Model: 8900
PIN: N/A
Carrier: Vodaphone
Posts: 11
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
mabin
New Member
 
Join Date: Sep 2009
Model: 7100t
PIN: N/A
Carrier: o2
Posts: 5
Default

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



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


3.3ft PT100 RTD Temperature Sensor Probe 3 Wires Cable Thermocouple picture

3.3ft PT100 RTD Temperature Sensor Probe 3 Wires Cable Thermocouple

$18.65



K-Type Thermocouple Probe Digital Thermometer Steel Sensor Spiral Cable  picture

K-Type Thermocouple Probe Digital Thermometer Steel Sensor Spiral Cable

$11.49



-58 to 2372 °F Ceramic Kiln Probe Type K Thermocouple Core Dia 2.0mm picture

-58 to 2372 °F Ceramic Kiln Probe Type K Thermocouple Core Dia 2.0mm

$9.99



Digital Thermometer Dual Channel Input Thermocouple K J T E R N C/F Selection US picture

Digital Thermometer Dual Channel Input Thermocouple K J T E R N C/F Selection US

$25.99



Heavy duty Thermocouple (60 Inch) Blodgett 3835 nickel  plated for pizza ovens picture

Heavy duty Thermocouple (60 Inch) Blodgett 3835 nickel plated for pizza ovens

$14.99



6802 II Digital Thermocouple Thermometer Dual Channel 2*K-Type Temperature Meter picture

6802 II Digital Thermocouple Thermometer Dual Channel 2*K-Type Temperature Meter

$24.40







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