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

NEW IN BOX NORGREN 110/120V SOLENOID VALVE V61R517A-A218JB
$96.61
NEW IN BOX NORGREN 110/120V SOLENOID VALVE V61R517A-A218JB pictureASCO 8262D22 SOLENOID COIL VALVE 110/120V *USED*
$27.0
ASCO 8262D22 SOLENOID COIL VALVE 110/120V *USED* pictureMac Valve PME-591JA Solenoid Valve 24VDC 2.5W With mPm B-12 Connector Used
$19.99
Mac Valve PME-591JA Solenoid Valve 24VDC 2.5W With mPm B-12 Connector Used pictureNEW ASCO 8320066 RED-HAT 120V-AC 1/4IN NPT SOLENOID VALVE D599678
$40.0
NEW ASCO 8320066 RED-HAT 120V-AC 1/4IN NPT SOLENOID VALVE D599678 pictureMac Valve 35A-AAA-DDBA-1BA Solenoid Valve 12VDC 6W Coil Used With Warranty
$19.99
Mac Valve 35A-AAA-DDBA-1BA Solenoid Valve 12VDC 6W Coil Used With Warranty picture






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