Java中文与ASCII码的转换

今天在研究Java中编码的时候,看到了Java中ascii码的强大。写了一个CoderUtils.java,以后会扩展它。

 

 package com.xingxd.study.test; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.io.PrintWriter; /** * @date 2009-3-11 * @author Xing,Xiudong * @Email:xingxiuodng[at]gmail.com * @index:http://blog.csdn.net/xxd851116 */ public class CoderUtils { public static char ascii2Char(int ASCII) { return (char) ASCII; } public static int char2ASCII(char c) { return (int) c; } public static String ascii2String(int[] ASCIIs) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < ASCIIs.length; i++) { sb.append((char) ascii2Char(ASCIIs[i])); } return sb.toString(); } public static String ascii2String(String ASCIIs) { String[] ASCIIss = ASCIIs.split(","); StringBuffer sb = new StringBuffer(); for (int i = 0; i < ASCIIss.length; i++) { sb.append((char) ascii2Char(Integer.parseInt(ASCIIss[i]))); } return sb.toString(); } public static int[] string2ASCII(String s) {// 字符串转换为ASCII码 if (s == null || "".equals(s)) { return null; } char[] chars = s.toCharArray(); int[] asciiArray = new int[chars.length]; for (int i = 0; i < chars.length; i++) { asciiArray[i] = char2ASCII(chars[i]); } return asciiArray; } public static String getIntArrayString(int[] intArray) { return getIntArrayString(intArray, ","); } public static String getIntArrayString(int[] intArray, String delimiter) { StringBuffer sb = new StringBuffer(); for (int i = 0; i < intArray.length; i++) { sb.append(intArray[i]).append(delimiter); } return sb.toString(); } public static String getASCII(int begin, int end) { StringBuffer sb = new StringBuffer(); for (int i = begin; i < end; i++) { sb.append(i).append(":").append((char) i).append("/t"); // sb.append((char) i).append("/t"); if (i % 10 == 0) { sb.append("/n"); } } return sb.toString(); } public static String getCHASCII(int begin, int end) { return getASCII(19968, 40869); } public static void showASCII(int begin, int end) { for (int i = begin; i < end; i++) { // System.out.print(i + ":" + (char) i + "/t"); System.out.print((char) i + "/t"); if (i % 10 == 0) { System.out.println(); } } } public static void showCHASCII() { showASCII(19968, 40869); } public static void showIntArray(int[] intArray) { showIntArray(intArray, ","); } public static void showIntArray(int[] intArray, String delimiter) { for (int i = 0; i < intArray.length; i++) { System.out.print(intArray[i] + delimiter); } } public static void createFile(String filePathAndName, String fileContent) throws IOException { String filePath = filePathAndName; filePath = filePath.toString(); File myFilePath = new File(filePath); if (!myFilePath.exists()) { myFilePath.createNewFile(); } FileWriter resultFile = new FileWriter(myFilePath); PrintWriter myFile = new PrintWriter(resultFile); String strContent = fileContent; myFile.println(strContent); myFile.close(); resultFile.close(); } public static void main(String[] args) throws IOException { String s = "好好学习!天天向上!————笑的自然 2009年3月11日"; showIntArray(string2ASCII(s), " "); System.out.println(); System.out.println(ascii2String(string2ASCII(s))); createFile("c://console_ch.txt", getCHASCII(0, 50000)); } }

运行结果:

22909 22909 23398 20064 65281 22825 22825 21521 19978 65281 8212 8212 8212 8212 31505 30340 33258 28982 32 50 48 48 57 24180 51 26376 49 49 26085
好好学习!天天向上!————笑的自然 2009年3月11日

Java中文与ASCII码的互相转换,能够下载任何字符。如下一瞥:
33:! 34:" 35:# 36:$ 37:% 38:& 39:' 40:( 
41:) 42:* 43:+ 44:, 45:- 46:. 47:/ 48:0 49:1 50:2 
51:3 52:4 53:5 54:6 55:7 56:8 57:9 58:: 59:; 60:< 
61:= 62:> 63:? 64:@ 65:A 66:B 67:C 68:D 69:E 70:F 
71:G 72:H 73:I 74:J 75:K 76:L 77:M 78:N 79:O 80:P 
81:Q 82:R 83:S 84:T 85:U 86:V 87:W 88:X 89:Y 90:Z 
91:[ 92:/ 93:] 94:^ 95:_ 96:` 97:a 98:b 99:c 100:d 
101:e 102:f 103:g 104:h 105:i 106:j 107:k 108:l 109:m 110:n 
111:o 112:p 113:q 114:r 115:s 116:t 117:u 118:v 119:w 120:x 
121:y 122:z 123:{ 124:| 125:} 126:~ 127: 
9471:⓿ 9472:─ 9473:━ 9474:│ 9475:┃ 9476:┄ 9477:┅ 9478:┆ 9479:┇ 9480:┈ 
9481:┉ 9482:┊ 9483:┋ 9484:┌ 9485:┍ 9486:┎ 9487:┏ 9488:┐ 9489:┑ 9490:┒ 
9491:┓ 9492:└ 9493:┕ 9494:┖ 9495:┗ 9496:┘ 9497:┙ 9498:┚ 9499:┛ 9500:├ 
9501:┝ 9502:┞ 9503:┟ 9504:┠ 9505:┡ 9506:┢ 9507:┣ 9508:┤ 9509:┥ 9510:┦ 
9511:┧ 9512:┨ 9513:┩ 9514:┪ 9515:┫ 9516:┬ 9517:┭ 9518:┮ 9519:┯ 9520:┰ 
9521:┱ 9522:┲ 9523:┳ 9524:┴ 9525:┵ 9526:┶ 9527:┷ 9528:┸ 9529:┹ 9530:┺ 
9531:┻ 9532:┼ 9533:┽ 9534:┾ 9535:┿ 9536:╀ 9537:╁ 9538:╂ 9539:╃ 9540:╄ 
9541:╅ 9542:╆ 9543:╇ 9544:╈ 9545:╉ 9546:╊ 9547:╋ 9548:╌ 9549:╍ 9550:╎ 
9551:╏ 9552:═ 9553:║ 9554:╒ 9555:╓ 9556:╔ 9557:╕ 9558:╖ 9559:╗ 9560:╘ 
9561:╙ 9562:╚ 9563:╛ 9564:╜ 9565:╝ 9566:╞ 9567:╟ 9568:╠ 9569:╡ 9570:╢ 
9571:╣ 9572:╤ 9573:╥ 9574:╦ 9575:╧ 9576:╨ 9577:╩ 9578:╪ 9579:╫ 9580:╬ 
9581:╭ 9582:╮ 9583:╯ 9584:╰ 9585:╱ 9586:╲ 9587:╳ 9588:╴ 9589:╵ 9590:╶ 
9591:╷ 9592:╸ 9593:╹ 9594:╺ 9595:╻ 9596:╼ 9597:╽ 9598:╾ 9599:╿ 9600:▀ 
9601:▁ 9602:▂ 9603:▃ 9604:▄ 9605:▅ 9606:▆ 9607:▇ 9608:█ 9609:▉ 9610:▊ 
9611:▋ 9612:▌ 9613:▍ 9614:▎ 9615:▏ 9616:▐ 9617:░ 9618:▒ 9619:▓ 9620:▔ 

12361:ぉ 12362:お 12363:か 12364:が 12365:き 12366:ぎ 12367:く 12368:ぐ 12369:け 12370:げ 
12371:こ 12372:ご 12373:さ 12374:ざ 12375:し 12376:じ 12377:す 12378:ず 12379:せ 12380:ぜ 
12381:そ 12382:ぞ 12383:た 12384:だ 12385:ち 12386:ぢ 12387:っ 12388:つ 12389:づ 12390:て 
12391:で 12392:と 12393:ど 12394:な 12395:に 12396:ぬ 12397:ね 12398:の 12399:は 12400:ば 
12401:ぱ 12402:ひ 12403:び 12404:ぴ 12405:ふ 12406:ぶ 12407:ぷ 12408:へ 12409:べ 12410:ぺ 
12411:ほ 12412:ぼ 12413:ぽ 12414:ま 12415:み 12416:む 12417:め 12418:も 12419:ゃ 12420:や 
12421:ゅ 12422:ゆ 12423:ょ 12424:よ 12425:ら 12426:り 12427:る 12428:れ 12429:ろ 12430:ゎ 
12431:わ 12432:ゐ 12433:ゑ 12434:を 12435:ん 12436:ゔ 12437:ゕ 12438:ゖ 12439:゗ 12440:゘ 
12441:゙ 12442:゚ 12443:゛ 12444:゜ 12445:ゝ 12446:ゞ 12447:ゟ 12448:゠ 12449:ァ 12450:ア 
12451:ィ 12452:イ 12453:ゥ 12454:ウ 12455:ェ 12456:エ 12457:ォ 12458:オ 12459:カ 12460:ガ 
12461:キ 12462:ギ 12463:ク 12464:グ 12465:ケ 12466:ゲ 12467:コ 12468:ゴ 12469:サ 12470:ザ 
12471:シ 12472:ジ 12473:ス 12474:ズ 12475:セ 12476:ゼ 12477:ソ 12478:ゾ 12479:タ 12480:ダ 
12481:チ 12482:ヂ 12483:ッ 12484:ツ 12485:ヅ 12486:テ 12487:デ 12488:ト 12489:ド 12490:ナ 
12491:ニ 12492:ヌ 12493:ネ 12494:ノ 12495:ハ 12496:バ 12497:パ 12498:ヒ 12499:ビ 12500:ピ 
12501:フ 12502:ブ 12503:プ 12504:ヘ 12505:ベ 12506:ペ 12507:ホ 12508:ボ 12509:ポ 12510:マ 
12511:ミ 12512:ム 12513:メ 12514:モ 12515:ャ 12516:ヤ 12517:ュ 12518:ユ 12519:ョ 12520:ヨ 
12521:ラ 12522:リ 12523:ル 12524:レ 12525:ロ 12526:ヮ 12527:ワ 12528:ヰ 12529:ヱ 12530:ヲ 
12531:ン 12532:ヴ 12533:ヵ 12534:ヶ 12535:ヷ 12536:ヸ 12537:ヹ 12538:ヺ 12539:・ 12540:ー 
12541:ヽ 12542:ヾ 12543:ヿ 12544:㄀ 12545:㄁ 12546:㄂ 12547:㄃ 12548:㄄ 12549:ㄅ 12550:ㄆ 
12551:ㄇ 12552:ㄈ 12553:ㄉ 12554:ㄊ 12555:ㄋ 12556:ㄌ 12557:ㄍ 12558:ㄎ 12559:ㄏ 12560:ㄐ 
12561:ㄑ 12562:ㄒ 12563:ㄓ 12564:ㄔ 12565:ㄕ 12566:ㄖ 12567:ㄗ 12568:ㄘ 12569:ㄙ 12570:ㄚ 
12571:ㄛ 12572:ㄜ 12573:ㄝ 12574:ㄞ 12575:ㄟ 12576:ㄠ 12577:ㄡ 12578:ㄢ 12579:ㄣ

1661:ٽ 1662:پ 1663:ٿ 1664:ڀ 1665:ځ 1666:ڂ 1667:ڃ 1668:ڄ 1669:څ 1670:چ 
1671:ڇ 1672:ڈ 1673:ډ 1674:ڊ 1675:ڋ 1676:ڌ 1677:ڍ 1678:ڎ 1679:ڏ 1680:ڐ 
1681:ڑ 1682:ڒ 1683:ړ 1684:ڔ 1685:ڕ 1686:ږ 1687:ڗ 1688:ژ 1689:ڙ 1690:ښ 
1691:ڛ 1692:ڜ 1693:ڝ 1694:ڞ 1695:ڟ 1696:ڠ 1697:ڡ 1698:ڢ 1699:ڣ 1700:ڤ 
1701:ڥ 1702:ڦ 1703:ڧ 1704:ڨ 1705:ک 1706:ڪ 1707:ګ 1708:ڬ 1709:ڭ 1710:ڮ 
1711:گ 1712:ڰ 1713:ڱ 1714:ڲ 1715:ڳ 1716:ڴ 1717:ڵ 1718:ڶ 1719:ڷ 1720:ڸ 
1721:ڹ 1722:ں 1723:ڻ 1724:ڼ 1725:ڽ 1726:ھ 1727:ڿ 1728:ۀ 1729:ہ 1730:ۂ 
1731:ۃ 1732:ۄ 1733:ۅ 1734:ۆ 1735:ۇ 1736:ۈ 1737:ۉ 1738:ۊ 1739:ۋ 1740:ی 
1741:ۍ 1742:ێ 1743:ۏ 1744:ې 1745:ۑ 1746:ے 1747:ۓ 1748:۔ 1749:ە 1750:ۖ 

9311:⑟ 9312:① 9313:② 9314:③ 9315:④ 9316:⑤ 9317:⑥ 9318:⑦ 9319:⑧ 9320:⑨ 
9321:⑩ 9322:⑪ 9323:⑫ 9324:⑬ 9325:⑭ 9326:⑮ 9327:⑯ 9328:⑰ 9329:⑱ 9330:⑲ 
9331:⑳ 9332:⑴ 9333:⑵ 9334:⑶ 9335:⑷ 9336:⑸ 9337:⑹ 9338:⑺ 9339:⑻ 9340:⑼ 
9341:⑽ 9342:⑾ 9343:⑿ 9344:⒀ 9345:⒁ 9346:⒂ 9347:⒃ 9348:⒄ 9349:⒅ 9350:⒆ 
9351:⒇ 9352:⒈ 9353:⒉ 9354:⒊ 9355:⒋ 9356:⒌ 9357:⒍ 9358:⒎ 9359:⒏ 9360:⒐ 
9361:⒑ 9362:⒒ 9363:⒓ 9364:⒔ 9365:⒕ 9366:⒖ 9367:⒗ 9368:⒘ 9369:⒙ 9370:⒚ 

9824:♠ 9825:♡ 9826:♢ 9827:♣ 9828:♤ 9829:♥ 9830:♦ 9786:☺ 9787:☻ 9788:☼ ◢ 9699:◣ 9700:◤ 9701:◥ 

12832:㈠ 12833:㈡ 12834:㈢ 12835:㈣ 12836:㈤ 12837:㈥ 12838:㈦ 12839:㈧ 12840:㈨

汉字部分:

19971:七 19972:丄 19973:丅 19974:丆 19975:万 19976:丈 19977:三 19978:上 19979:下 19980:丌 
19981:不 19982:与 19983:丏 19984:丐 19985:丑 19986:丒 19987:专 19988:且 19989:丕 19990:世 
19991:丗 19992:丘 19993:丙 19994:业 19995:丛 19996:东 19997:丝 19998:丞 19999:丟 20000:丠 
20001:両 20002:丢 20003:丣 20004:两 20005:严 20006:並 20007:丧 20008:丨 20009:丩 20010:个 
20011:丫 20012:丬 20013:中 20014:丮 20015:丯 20016:丰 20017:丱 20018:串 20019:丳 20020:临 
20021:丵 20022:丶 20023:丷 20024:丸 20025:丹 20026:为 20027:主 20028:丼 20029:丽 20030:举 
20031:丿 20032:乀 20033:乁 20034:乂 20035:乃 20036:乄 20037:久 20038:乆 20039:乇 20040:么 
20041:义 20042:乊 20043:之 20044:乌 20045:乍 20046:乎 20047:乏 20048:乐 20049:乑 20050:乒 
20051:乓 20052:乔 20053:乕 20054:乖 20055:乗 20056:乘 20057:乙 20058:乚 20059:乛 20060:乜 
20061:九 20062:乞 20063:也 20064:习 20065:乡 20066:乢 20067:乣 20068:乤 20069:乥 20070:书 
20071:乧 20072:乨 20073:乩 20074:乪 20075:乫 20076:乬 20077:乭 20078:乮 20079:乯 20080:买 
20081:乱 20082:乲 20083:乳 20084:乴 20085:乵 20086:乶 20087:乷 20088:乸 20089:乹 20090:乺 
20091:乻 20092:乼 20093:乽 20094:乾 20095:乿 20096:亀 20097:亁 20098:亂 20099:亃 20100:亄 
20101:亅 20102:了 20103:亇 20104:予 20105:争 20106:亊 20107:事 20108:二 20109:亍 20110:于 
20111:亏 20112:亐 20113:云 20114:互 20115:亓 20116:五 20117:井 20118:亖 20119:亗 20120:亘 

 

 

转载于:https://www.cnblogs.com/xingxiudong/archive/2009/03/11/3987110.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/463568.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

第四周:机器学习知识点回顾

前言&#xff1a; 讲真&#xff0c;复习这块我是比较头大的&#xff0c;之前的线代、高数、概率论、西瓜书、樱花书、NG的系列课程、李宏毅李沐等等等等…那可是花了三年学习佳实践下来的&#xff0c;现在一想脑子里就剩下几个名词就觉得废柴一个了&#xff0c;朋友们有没有同感…

移植linux内核到i.MX6ULL过程

本文描述移植NXP官方 linux 5.4 内核到i.MX6ULL开发板。一、NXP官方linux内核1. 下载 NXP官方linux仓库地址为&#xff1a;https://github.com/Freescale/linux-fslc/tree/5.4-2.1.x-imx。选择该分支下载zip包即可&#xff0c;不要整个仓库下载&#xff0c;太大了&#xff1a;2…

Go语言之进阶篇http服务器获取客户端的一些信息

1、http服务器获取客户端的一些信息 示例: package mainimport ("fmt""net/http" )//w, 给客户端回复数据 //r, 读取客户端发送的数据 func HandConn(w http.ResponseWriter, r *http.Request) {fmt.Println("r.Method ", r.Method)fmt.Println…

R学习之——R用于文本挖掘(tm包)

首先需要安装并加载tm包。 1、读取文本 x readLines("222.txt") 2、建立语料库 > rCorpus(VectorSource(x))> rA corpus with 7012 text documents 3、语料库输出&#xff0c;保存到硬盘 > writeCorpus(r) 4、查看语料库 > print(r) A corpus with 7012…

C#索引器(二)

索引器允许类和结构的实例按照与数组相同的方式进行索引&#xff0c;索引器类似与属性&#xff0c;不同之处在于他们的访问器采用参数。被称为有参属性。 简单的索引器实例&#xff1a; 索引器与属性的比较&#xff1a; 标示方式&#xff1a;属性以名称来标识&#xff0c;索引器…

C++中的定位放置new(placement new)

转载&#xff1a;https://www.cnblogs.com/weekbo/p/8533368.html 今天在使用new时&#xff0c;需要使用特定位置的一块内存&#xff0c;因此查了资料&#xff0c;发现该文章有帮助就现转载做一个备份。 一般来说&#xff0c;使用new申请空间时&#xff0c;是从系统的“堆”&…

学了STM32要继续学习Linux吗?

关注我的读者中&#xff0c;有很大一部分是单片机&#xff08;STM32&#xff09;的开发者&#xff0c;经常看到有人问类似的问题&#xff1a;学了STM32要继续学习Linux吗&#xff1f;每个人的情况不同&#xff0c;到底要不要学习Linux&#xff0c;要结合自身的情况。有的人已经…

win7域内桌面黑屏

网络环境: win2k3域 客户端: win7, win2k8 现象: 登录域后&#xff0c;桌面背景是黑色&#xff0c;所有点击会变双击 微软对这个问题已经有了介绍&#xff0c;而且出了补丁。 http://support.microsoft.com/kb/977944转载于:https://blog.51cto.com/kzhou/932680

在Javascript中实现伪哈希表

了解数据结构的人应该都听说过哈希表这种数据结构&#xff0c;它是一种典型的利用键值对存储并检索数据的一种非线性结构&#xff0c;又称散列表或杂凑法。在一般的线性表结构中&#xff0c;数据的相对位置是随机的&#xff0c;即数据和用于检索的关键字之间不存在确定的关系&a…

模板函数与特化函数

本文转自&#xff1a;https://www.cnblogs.com/dracohan/p/3401660.html 转来收藏以便查阅&#xff0c;感谢原作者 今天在写代码时&#xff0c;遇到了模板和特化&#xff0c;在网上找了资料后问题呗一一解决&#xff0c;转载此文用于以后查阅&#xff0c;感谢原创者。其中增加…

这样调试内核启动流程

内核生命周期uboot 打印完 Starting kernel . . .&#xff0c;就完成了自己的使命&#xff0c;控制权便交给了 kernel 的第一条指令&#xff0c;也就是下面这个函数init/main.casmlinkage __visible void __init start_kernel(void){...rest_init();}start_kernel 相当于内核的…

iview实现多文件上传,前段到后台

前段 业务是 分别上传两个文件 &#xff1a;1.一个报告 一个 表格&#xff0c;而且限制了格式 报告为doc 表格为xsl2.有别的参数 也要&#xff0c;比如&#xff0c;上传人&#xff0c;上传日期&#xff0c;中心名称 这样的话&#xff0c;我们无法使用 iview 的直接上传&#x…

ios 图片添加阴影

2019独角兽企业重金招聘Python工程师标准>>> UIimageView *imageView [[UIImageView alloc ] init]; imageView.layer.shadowColor [UIColor blackColor].CGColor; imageView.layer.shadowOffset CGSizeMake(3,2); imageView.layer.shadowOpacity 0.6; imageVie…

asp.net定时执行任务-解决应用池回收问题----转载

在复杂的业务应用程序中&#xff0c;有时候会要求一个或者多个任务在一定的时间或者一定的时间间隔内计划进行&#xff0c;比如定时备份或同步数据库&#xff0c;定时发送电子邮件&#xff0c;定期处理用户状态信息&#xff0c;支付系统中定期同步异常账单等等&#xff0c;我们…

bool与string互转

今天在工作中遇到了将string转换成bool类型数据&#xff0c;查阅了工具书解决了问题&#xff0c;现将注意要点总结如下&#xff1a; 增加头文件&#xff1a;#include <sstream> 代码如下&#xff1a; 在codeblocks软件上测试结果如下&#xff1a; 使用者需要根据自己的实…

Go语言之高级篇beego框架之参数配置与路由配置

一、参数配置 beego默认会解析当前应用下的conf/app.conf文件 1.1、beego的参数配置 appname WEB httpport 8080 runmode dev 几种开发模式 [dev] httpprot 8080 [prod] httpport 8081 [test] httpport 8082 //备注&#xff1a; beego.AppConfig.String( "dev::m…

C++ int转string以及源码

今天遇到一个int类型数据转换为string&#xff0c;查了资料在c11标准中增加了全局函数std::to_string来实现该功能&#xff1a; string to_string (int val); string to_string (long val); string to_string (long long val); string to_string (unsigned val); string t…

OpenXLive 0.9.9 SDK发布,增加对SNS的支持

相信iOS和Android的游戏玩家对于OpenFeint都会比较熟悉&#xff0c;在北京有着这样的一个团队&#xff0c;他们一直在专注于Windows Phone平台上的第三方游戏社交平台的开发&#xff0c;这个产品叫做OpenXlive&#xff0c;近期发布了其SDK的0.9.9版本&#xff0c;并增加了向Twi…

Asp.Net MVC1.0正式版发布

下载地址: http://www.microsoft.com/downloads/details.aspx?FamilyID53289097-73ce-43bf-b6a6-35e00103cb4b&displaylangen 相对RC2版的变化不大&#xff0c;仅二点: 1.Jquery从1.3.1升级为1.3.2版本 2.修正了MVC Web应用程序中创建Silverlight时因项目不可用而出错的BU…

EUREKA原理总结

Eureka高可用架构 https://github.com/Netflix/eureka/wiki/Eureka-at-a-glance 上图中主要的名称说明&#xff1a; Register&#xff1a;EurekaClient注册&#xff08;Http请求&#xff09;到EurekaServer&#xff0c;EurekaClient会发送自己元数据(ip,port,主页等)&#xff0…