Java语言 - Unicode编码与字符串互转

news/2024/10/29 2:29:18/

概述

        项目需要Unicode编码与字符串互转,在此做个笔录。

1、code

// Press Shift twice to open the Search Everywhere dialog and type `show whitespaces`,
// then press Enter. You can now see whitespace characters in your code.
public class Main {public static void main(String[] args) {// Press Alt+Enter with your caret at the highlighted text to see how// IntelliJ IDEA suggests fixing it.System.out.println("Hello and welcome!");String strArray[] = {"嘿嘿嘿hahaha001122", "123456789"};for (int i = 0; i < strArray.length; i++) {System.out.println("***************** stringToUnicode *****************");String unicode = stringToUnicode(strArray[i]);System.out.println("stringToUnicode:" + unicode);System.out.println("***************** unicodeToString *****************");String uniStr = unicodeToString(unicode);System.out.println("unicodeToString:" + uniStr + "\n");}}public static String unicodeToString(String unicode) {StringBuffer string = new StringBuffer();/* 以 \ u切割 */String[] hex = unicode.split("\\\\u");for (int i = 1; i < hex.length; i++) {/* 这里代表将值转为16进制表示,一共有2, 8, 10, 16几种表示 */int data = Integer.parseInt(hex[i], 16);/* 追加成String */string.append((char) data);}return string.toString();}public static String stringToUnicode(String string) {StringBuffer unicode = new StringBuffer();for (int i = 0; i < string.length(); i++) {/* 取出每一个字符 */char c = string.charAt(i);/* 转换为unicode Integer.toHexString(); 返回字符的16进制表示 */unicode.append("\\u" + Integer.toHexString(c));}return unicode.toString();}
}

2、运行结果

3、总结

        希望能帮助到需要的攻城狮,谢谢观阅!!! 


http://www.ppmy.cn/news/742791.html

相关文章

DR模式部署LVS负载均衡集群

目录 一、配置负载调度器 1.配置虚拟 IP 地址&#xff08;VIP&#xff1a;192.168.146.180&#xff09; 2.调整 proc 响应参数 3. 配置负载分配策略 ​编辑二、部署共享存储&#xff08;NFS服务器&#xff1a;192.168.146.20&#xff09; 三、配置节点服务器 1.配置虚拟…

9、DataX安装部署

1、 DataX简介 1.1 DataX概述 DataX 是阿里巴巴开源的一个异构数据源离线同步工具&#xff0c;致力于实现包括关系型数据库(MySQL、Oracle等)、HDFS、Hive、ODPS、HBase、FTP等各种异构数据源之间稳定高效的数据同步功能。 源码地址&#xff1a;https://github.com/alibaba/…

数据结构--串的存储结构

数据结构–串的存储结构 串的顺序存储 静态数组实现(定长顺序存储) #define MAXLEN 255 typedef struct {char ch[MAXLEN];int length; }SString;动态数组实现(堆分配存储) typedef struct {char* ch;int length; }HString;int main() {HString S;S.ch (char*)malloc(sizeo…

影响wifi信号强度因素

影响WIFI信号强度因素&#xff1a; 1、室内错综复杂的环境&#xff0c;会在一定程度上导致WIFI无线信号产生多径传播现象&#xff0c;从而导致信号强度的不稳定性&#xff1b; 2、室内的人员密集程度和人员流动情况也会对WIFI信号强度产生影响&#xff1b; 3、室内电子产品产生…

Android wifi 信号强度单位 dbm

当利用android wifi模块获取wifi信号强度值时我们通常会得到-20~-80之间的值&#xff0c;单位是dBm。如&#xff1a;-67dBm。 那么什么是dBm呢&#xff1f; dBm 是表示功率绝对值大小的值&#xff0c;是以1mW功率为基准的一个比值。计算公式为&#xff1a;dBm10log&#xff0…

获取wifi当前手机连接的wifi信息以及信号强度

修改时间&#xff1a;2022/9/5 案例中是主动向安卓系统获取wifi信号强度&#xff0c;正常情况下是通过监听广播的方式来被动获取&#xff0c;看自己三年前写的代码还是挺好笑的&#xff0c;看到好多问题&#xff0c;再不改就误人子弟了&#xff0c;所以改了改。 给权限 <u…

wifi信号强度等级算法

源于android 源码 /frameworks/base/wifi/java/android/net/wifi/WifiManager.java ... /** Anything worse than or equal to this will show 0 bars. */private static final int MIN_RSSI -100;/** Anything better than or equal to this will show the max bars. */pri…

【转】如何检测wifi信号强度? -- 不错

原文网址&#xff1a;http://jingyan.baidu.com/article/90895e0fe9616164ec6b0b88.html 当我们在使用wifi上网时&#xff0c;在某些角落会出现无wifi信号&#xff0c;或是时有时无的状态。 今天我们就来用一款软件来帮助您测试wifi信号强度。 工具/原料 笔记本 WirelessMon.ex…