Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is something fishy here; either <code>text</code> is not a <code>String</code>, or you don't use <code>.replace()</code> but something else (<code>.replaceAll()</code>?), or Android's <code>.replace()</code> is buggy.</p> <p>And I frankly doubt that Android devs would have had such an overlook.</p> <p>The <a href="http://docs.oracle.com/javase/7/docs/api/java/lang/String.html#replace%28java.lang.CharSequence,%20java.lang.CharSequence%29" rel="nofollow">Javadoc for <code>String#replace()</code></a> says:</p> <blockquote> <p>Replaces each substring of this string that matches the <strong>literal target sequence</strong> with the specified <strong>literal replacement sequence.</strong> [emphasis mine]</p> </blockquote> <p>Unlike its sibling methods (<code>.replaceFirst()</code> and <code>.replaceAll()</code>) which do use regexes, <code>.replace()</code> doesn't (and the fact that internally it does use <code>Pattern</code>, at least in Oracle's JDK [*], is not the problem).</p> <p>Therefore, if you actually use <code>.replace()</code> and gain the result you say, this is a bug in Android. If this is the case, try an alternative, like so (UNTESTED):</p> <pre><code>public static String realStringReplace(final String victim, final String target, final String replacement) { final int skip = target.length(); final StringBuilder sb = new StringBuilder(victim.length()); String tmp = victim; int index; while (!tmp.isEmpty()) { index = tmp.indexOf(target); if (index == -1) break; sb.append(tmp.subString(0, index)).append(replacement); tmp = tmp.subString(index + skip); } return sb.append(tmp).toString(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload