regex - Java replaceAll cannot replace a character in a string -
i want replace arabic letter heh (u+0647) arabic letter ae (u+06d5) in given string using java replaceall(regex, replacement)
method. have code:
string arabicheh = "\u0647"; // arabic letter heh string arabicae = "\u06d5"; // arabic letter ae string text = txtpane.gettext(); string newtext = text.replaceall(arabicheh, arabicae);
when print newtext
variable nothing changed, letter arabicheh
still exist in string.
note: code works when write in way:
string newtext = text.replaceall("ه", arabicae);
in other words, code works when make arabic letter heh parameter replaceall(regex, replacement)
, don't want write character "ه"
inside code because not ides can read/show character.
i think arabibheh
has problem, because text.contains(arabicheh)
evaluates false
while contains arabicheh
, thought may problem in getting text jtextpane
(string text = txtpane.gettext();
) when print text
console same text typed in jtextpane
, including arabicheh
.
anyone kindly can explain why text.contains(arabicheh)
evaluates false
or why code not working in text.replaceall(arabicheh, arabicae)
?
when copypasted snippet i've got space after \u0647
string arabicheh = "\u0647 "; // arabic letter heh
it https://en.wikipedia.org/wiki/zero-width_non-joiner
just remove code snippet , work :)
Comments
Post a Comment