Forum     

Go Back   Digit Technology Discussion Forum > Software > Programming
Register FAQ Calendar Mark Forums Read

Programming The destination for developers - C, C++, Java, Python and the lot


Closed Thread
 
LinkBack Thread Tools Display Modes
Old 07-04-2008, 06:52 AM   #1 (permalink)
Right Off the Assembly Line
 
estranged12's Avatar
 
Join Date: Aug 2006
Posts: 28
Default String.replace


I am trying to use the string.replace function to replace one character of a string to a sequence of others.
Like this
Say i have a simple string called draw.
String draw = "F";
System.out.println(draw);
draw.replace("F","F-F+F+F-F");
System.out.println(draw);

The output is
F
F

What do I do to allow it to change the F to F-F+F+F-F (and then later all the Fs in that string to be F-F+F+F-F recursively), because the string.replace function doesnt work.

Thanks
estranged12 is offline  
Advertisements. Register and be a member of the community to get rid of them.
Advertisement

Old 07-04-2008, 07:49 AM   #2 (permalink)
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: String.replace

<String>.replace("Str1","Str2") RETURNS a string, and does not change the actual string.

So your code's gotta be:
Code:
class M
{
    public static void main(String args[])
    {
        String a = "Hi";
        a = a.replace("F","F-F+F+F-F");
        System.out.println(a);
    }
}
By recursively do you mean that even the replaced F must be re-replaced with F-F+F+F-F? I don't see why you wish to do that infinite thing but it can be achieved via a simple While(True) kind of loop..
__________________
Harsh J
www.harshj.com
QwertyManiac is offline  
Old 09-04-2008, 09:58 AM   #3 (permalink)
In The Zone
 
ruturaj3's Avatar
 
Join Date: Feb 2007
Location: Mumbai
Posts: 214
Default Re: String.replace

Or u can use StringBuilder instead of String class, bcoz it is mutable.
ruturaj3 is offline  
Closed Thread

Bookmarks

Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
C++ String to all conversion.... Help needed... aditya.shevade Programming 8 06-03-2008 11:33 PM
how to make the string function ? clmlbx Programming 3 25-02-2008 09:43 PM
how to extract the needed part from a string in vb.net *GandaBerunda* Programming 3 05-11-2007 01:05 PM
cant declare a string variable... geekgod Open Source 13 12-08-2006 06:09 AM
asp 'replace' string query! 144 QnA (read only) 1 30-06-2006 10:35 AM

 
Latest Threads
- by Charan
- by Sarath
- by clmlbx

Advertisement




All times are GMT +5.5. The time now is 12:57 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.

Search Engine Optimization by vBSEO 3.3.2