Status
Not open for further replies.

estranged12

Broken In
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
 

QwertyManiac

Commander in Chief
<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";
        [B]a = a.replace[/B]("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..
 
Status
Not open for further replies.
Top Bottom