2015-10-15 51 views
0

我有一個包含一個字符串:½的Java檢查字符串特殊字符

從我明白我相信的,這是\uFFFD

有人可以幫助我,爲什麼這個語法不起作用:

if (promotions.getText().contains("\uFFFD")) { 
       return promotions; 
} 
+0

的可能的複製[我如何檢測Java字符串Unicode字符?(http://stackoverflow.com/questions/1673544/how-do-i-detect- unicode-characters-in-a-java-string) –

+0

什麼是錯誤? –

+1

@dguay不需要。 –

回答

2

½是\ u00BD

所以這應該工作

if (promotions.getText().contains("\u00BD")) { 
0

試試這個:

if (promotions.getText().contains("\u00BD")) 
{ 
    return promotions; 
} 
+0

雖然這可能在理論上回答這個問題,但這並不是一個好的答案,因爲它沒有教導OP。相反,它給出了一個沒有解釋的替代方案這通常會導致OP沒有學習,並且在發生類似問題時回到問一個新問題。你介意添加一些解釋嗎? – Vogel612

相關問題