Re: [問題] 有沒有方法將字串中的非英文部分轉成它 …

看板java作者 (-858993460)時間13年前 (2011/04/01 22:14), 編輯推噓1(101)
留言2則, 2人參與, 最新討論串1/1
※ 引述《yamamura (sadako)》之銘言: : 大家好 : 是這樣的,我做了一隻程式只想餵它英文,但很多句子裡面都同時包含多種語言 : 像中英文參雜等,它們都用utf8的格式儲存字符 : 想請問有沒有函數可以將非英數字的其他語系字符轉換成英數字型態的編碼格式 : 當然過程中原本是英數字的地方不會改變 : 先謝過各位高手了! 呃, 你這個需求還頗奇怪.... 在 java 裡 char 和 String 都是 unicode 所以你只要把它讀成 String 就可以套進去用 至於讀成 String 的方法 你可以先讀進 byte[] 再使用 new String(bytearray, Charset.forName("UTF-8")) 轉成 String 即可 -- 'You've sort of made up for it tonight,' said Harry. 'Getting the sword. Finishing the Horcrux. Saving my life.' 'That makes me sound a lot cooler then I was,' Ron mumbled. 'Stuff like that always sounds cooler then it really was,' said Harry. 'I've been trying to tell you that for years.' -- Harry Potter and the Deathly Hollows, P.308 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.112.30.138

04/01 22:25, , 1F
增加一點技巧,受教了,感恩^^
04/01 22:25, 1F

04/02 07:50, , 2F
Apache的CommonLang是你的好朋友
04/02 07:50, 2F
文章代碼(AID): #1DbTsh39 (java)