2012-10-12 12 views
0

希望使用特殊字符,例如:(£, ¥),這些鍵盤中沒有準備某些字符串。在Java中需要使用特殊字符(未在鍵盤中給出)

+1

嘗試alt + [任意鍵],看看結果是什麼。你看,鍵盤上有更多的字符,你可以看到 – 11684

+0

例如:alt + 1:¡,alt + 2,€,+3:£,+4:¢,+ y:¥ – 11684

+1

當我必須,我谷歌他們的名字和複製+粘貼到代碼。 –

回答

3

如果您知道字符的Unicode字符代碼,您可以使用\ uXXXX方法將字符放入代碼中的字符串中。

+0

我建議不要那樣做,因爲它很難閱讀。 – Philipp

+1

@ Philipp如果確實使用了這種字符,它仍然比使用編輯器字體中通常不支持的字符更好。 –

1

你真的應該使用UNICODE在Java代碼中像這樣的例子:從採取

//Use a string literal to assign a value to the String 
    String address = "I live at 22b Baker Street!"; 

    //The same string but using Unicode values 
    String unicodeAddress = "\u0049\u0020\u006C\u0069\u0076\u0065" 
      + "\u0020\u0061\u0074\u0020\u0032\u0032\u0042\u0020" 
      + "\u0042\u0061\u006B\u0065\u0072\u0020\u0053\u0074" 
      + "\u0072\u0065\u0065\u0074\u0021"; 

    System.out.println("Here is Sherlock's address: " + address); 
    System.out.println("It even works using Unicode characters: " + unicodeAddress); 

例。我發現this resource查找unicodes很有用。

它避免了與特殊字符編碼相關的各種問題。