作者LPH66 (-858993460)
看板java
标题Re: [问题] 有没有方法将字串中的非英文部分转成它 …
时间Fri Apr 1 22:14:01 2011
※ 引述《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
1F:推 yamamura:增加一点技巧,受教了,感恩^^ 04/01 22:25
2F:→ jej:Apache的CommonLang是你的好朋友 04/02 07:50