Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

When I use :

mString = mString.replace(" hello 123 everyone", "Yo");

It works fine. But if I use a mix of integer and strings and " " and then printLn it shows same output but it won't replace! Same thing with indexOf, if I use to many like " " + variable + more stuff, it won't find it.

The output is identical, this must be a bug in Java.

Anyone know?

share|improve this question

closed as too localized by Lion, casperOne Apr 14 '12 at 2:22

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers 2

public static void main(String[] args) {

    String s = "<h3>Fredag 20 april</h3>";
    int day = 20;   

    System.out.println(s);

    s = s.replace(" " + day, "hello!");

    System.out.println(s);
}

Output:

<h3>Fredag 20 april</h3>
<h3>Fredaghello! april</h3>

Working for me!

share|improve this answer

Are you saying that this doesn't work?

String mString = " hello 123 everyone";<br>
mString = mString.replace(" " + "hello " + 123 + " everyone", "Yo");<br>
System.out.println(mString);

Make sure you don't have any extra space on the original string.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.