发送中文短信
This commit is contained in:
3
my_error/ZHtoUnicode.py
Normal file
3
my_error/ZHtoUnicode.py
Normal file
@@ -0,0 +1,3 @@
|
||||
s = input().strip()
|
||||
unicode_codes = ''.join(f"{ord(c):04X}" for c in s)
|
||||
print(unicode_codes)
|
95
my_error/ZHunicodePro.py
Normal file
95
my_error/ZHunicodePro.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import tkinter as tk
|
||||
from tkinter import ttk, messagebox
|
||||
|
||||
def copy_to_clipboard():
|
||||
root.clipboard_clear()
|
||||
root.clipboard_append(output_var.get())
|
||||
messagebox.showinfo("成功", "已复制到剪贴板")
|
||||
|
||||
def convert_unicode(event=None):
|
||||
s = entry.get().strip()
|
||||
if not s:
|
||||
messagebox.showwarning("提示", "请输入内容")
|
||||
return
|
||||
|
||||
try:
|
||||
unicode_str = ''.join(f"{ord(c):04X}" for c in s)
|
||||
output_var.set(unicode_str)
|
||||
# copy_to_clipboard()
|
||||
except Exception as e:
|
||||
messagebox.showerror("错误", f"转换失败: {str(e)}")
|
||||
|
||||
|
||||
# 创建主窗口
|
||||
root = tk.Tk()
|
||||
root.title("Unicode转换器")
|
||||
root.geometry("300x300") # 正方形窗口
|
||||
# root.resizable(False, False)
|
||||
root.configure(bg="#f5f6fa")
|
||||
|
||||
# 修复的变量定义
|
||||
output_var = tk.StringVar()
|
||||
|
||||
# 现代界面样式配置
|
||||
style = ttk.Style()
|
||||
style.theme_use('clam')
|
||||
|
||||
# 自定义样式
|
||||
style.configure("TFrame", background="#f5f6fa")
|
||||
style.configure("TLabel",
|
||||
font=("微软雅黑", 11),
|
||||
background="#f5f6fa",
|
||||
foreground="#2d3436")
|
||||
style.configure("TEntry",
|
||||
font=("微软雅黑", 11),
|
||||
padding=5)
|
||||
style.configure("TButton",
|
||||
font=("微软雅黑", 10, "bold"),
|
||||
padding=8,
|
||||
foreground="#ffffff")
|
||||
style.map("TButton",
|
||||
background=[("active", "#0984e3"), ("!active", "#74b9ff")],
|
||||
foreground=[("active", "#ffffff"), ("!active", "#ffffff")])
|
||||
|
||||
# 主容器
|
||||
main_frame = ttk.Frame(root)
|
||||
main_frame.pack(expand=True, padx=30, pady=30)
|
||||
|
||||
# 输入区域
|
||||
input_frame = ttk.Frame(main_frame)
|
||||
input_frame.pack(pady=15, fill="x")
|
||||
|
||||
ttk.Label(input_frame, text="输入文本:").pack(side="left", padx=(0, 10))
|
||||
entry = ttk.Entry(input_frame, width=20)
|
||||
entry.pack(side="left", expand=True)
|
||||
entry.bind("<Return>", convert_unicode) # 绑定回车键
|
||||
|
||||
# 输出区域
|
||||
output_frame = ttk.Frame(main_frame)
|
||||
output_frame.pack(pady=20, fill="x")
|
||||
|
||||
ttk.Label(output_frame, text="转换结果:").pack(side="left", padx=(0, 10))
|
||||
output_entry = ttk.Entry(
|
||||
output_frame,
|
||||
textvariable=output_var,
|
||||
width=24,
|
||||
state="readonly",
|
||||
font=("Consolas", 12, "bold"),
|
||||
foreground="#2d3436"
|
||||
)
|
||||
output_entry.pack(side="left", expand=True)
|
||||
|
||||
# 按钮区域
|
||||
btn_frame = ttk.Frame(main_frame)
|
||||
btn_frame.pack(pady=30)
|
||||
|
||||
convert_btn = ttk.Button(btn_frame, text="立即转换", command=convert_unicode)
|
||||
convert_btn.pack(side="left", padx=10)
|
||||
|
||||
copy_btn = ttk.Button(btn_frame, text="复制结果", command=copy_to_clipboard)
|
||||
copy_btn.pack(side="left")
|
||||
|
||||
# 窗口居中
|
||||
root.eval('tk::PlaceWindow . center')
|
||||
|
||||
root.mainloop()
|
48
my_error/testunicodephone.cpp
Normal file
48
my_error/testunicodephone.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
#include<iostream>
|
||||
#include<algorithm>
|
||||
#include<cstring>
|
||||
using namespace std;
|
||||
void str_to_unicode(const char *input, uint8_t *output) {
|
||||
uint16_t unicode;
|
||||
uint8_t *ptr = output;
|
||||
while (*input) {
|
||||
// UTF-8 ת Unicode<64><65><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><C6BD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
if ((*input & 0xE0) == 0xE0) { // 3<>ֽ<EFBFBD>UTF-8<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>
|
||||
unicode = ((input[0] & 0x0F) << 12) | ((input[1] & 0x3F) << 6) | (input[2] & 0x3F);
|
||||
input += 3;
|
||||
} else if ((*input & 0xC0) == 0xC0) { // 2<>ֽ<EFBFBD>UTF-8<>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>չ<EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
||||
unicode = ((input[0] & 0x1F) << 6) | (input[1] & 0x3F);
|
||||
input += 2;
|
||||
} else { // 1<>ֽ<EFBFBD>ASCII<49>ַ<EFBFBD>
|
||||
unicode = *input;
|
||||
input += 1;
|
||||
}
|
||||
// ת<><D7AA>Ϊ<EFBFBD><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>UTF-16BE<42><45>
|
||||
*ptr++ = (unicode >> 8) & 0xFF;
|
||||
*ptr++ = unicode & 0xFF;
|
||||
}
|
||||
*ptr = '\0'; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
int main()
|
||||
{
|
||||
int n;
|
||||
// string s;
|
||||
uint8_t a[10005];
|
||||
char s[100005];
|
||||
// cin>>s;
|
||||
scanf("%s",s);
|
||||
int i=-1;
|
||||
char sc[1005];
|
||||
str_to_unicode(s,a);
|
||||
for(int i=0;i<=100;i++)
|
||||
{
|
||||
printf("%X",a[i]);
|
||||
}
|
||||
while(s[++i])
|
||||
{
|
||||
sprintf(sc+i*4,"00%X",s[i]);
|
||||
printf("00%X",s[i]);
|
||||
}
|
||||
printf("\n%s",sc);
|
||||
|
||||
}
|
99
my_error/uni3.cpp
Normal file
99
my_error/uni3.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
#include <stdio.h>
|
||||
#include <iostream>
|
||||
using namespace std;
|
||||
//void print_utf8_to_unicode(const char *str) {
|
||||
// while (*str) {
|
||||
// unsigned char c = *str;
|
||||
// unsigned int code = 0;
|
||||
//
|
||||
// // <20><><EFBFBD><EFBFBD>UTF-8<><38><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>
|
||||
// if (c < 0x80) { // 1<>ֽ<EFBFBD>
|
||||
// code = c;
|
||||
// str += 1;
|
||||
// } else if ((c & 0xE0) == 0xC0) { // 2<>ֽ<EFBFBD>
|
||||
// code = ((c & 0x1F) << 6) | (str[1] & 0x3F);
|
||||
// str += 2;
|
||||
// } else if ((c & 0xF0) == 0xE0) { // 3<>ֽڣ<D6BD><DAA3><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ã<EFBFBD>
|
||||
// code = ((c & 0x0F) << 12) | ((str[1] & 0x3F) << 6) | (str[2] & 0x3F);
|
||||
// str += 3;
|
||||
// } else if ((c & 0xF8) == 0xF0) { // 4<>ֽ<EFBFBD>
|
||||
// code = ((c & 0x07) << 18) | ((str[1] & 0x3F) << 12) | ((str[2] & 0x3F) << 6) | (str[3] & 0x3F);
|
||||
// str += 4;
|
||||
// } else {
|
||||
// // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ч<EFBFBD>ֽ<EFBFBD>
|
||||
// code = c; // Unicode<64>滻<EFBFBD>ַ<EFBFBD>
|
||||
// str++;
|
||||
// }
|
||||
//
|
||||
// printf("U+%04X ", code);
|
||||
// }
|
||||
//}
|
||||
|
||||
int Utf82Unicode(char* pInput, char* pOutput)
|
||||
{
|
||||
int outputSize = 0; //<2F><>¼ת<C2BC><D7AA><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Unicode<64>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD>
|
||||
*pOutput = 0;
|
||||
while (*pInput)
|
||||
{
|
||||
cout<< *pInput<<"; ";
|
||||
if (*pInput > 0x00 && *pInput <= 0x7F) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>UTF8<46>ַ<EFBFBD><D6B7><EFBFBD>Ӣ<EFBFBD><D3A2><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8><EFBFBD><EFBFBD><EFBFBD>֣<EFBFBD>
|
||||
{
|
||||
*pOutput = *pInput;
|
||||
pOutput++;
|
||||
*pOutput = 0; //С<>˷<EFBFBD><CBB7><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ڸߵ<DAB8>ַ<EFBFBD>0
|
||||
}
|
||||
else if (((*pInput) & 0xE0) == 0xC0) //<2F><><EFBFBD><EFBFBD>˫<EFBFBD>ֽ<EFBFBD>UTF8<46>ַ<EFBFBD>
|
||||
//else if(*pInput >= 0xC0 && *pInput < 0xE0)
|
||||
{
|
||||
char high = *pInput;
|
||||
pInput++;
|
||||
char low = *pInput;
|
||||
if ((low & 0xC0) != 0x80) //<2F><><EFBFBD><EFBFBD><EFBFBD>Ƿ<EFBFBD>Ϊ<EFBFBD>Ϸ<EFBFBD><CFB7><EFBFBD>UTF8<46>ַ<EFBFBD><D6B7><EFBFBD>ʾ
|
||||
{
|
||||
return -1; //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
}
|
||||
|
||||
*pOutput = (high << 6) + (low & 0x3F);
|
||||
pOutput++;
|
||||
*pOutput = (high >> 2) & 0x07;
|
||||
}
|
||||
else if (((*pInput) & 0xF0) == 0xE0) //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD>UTF8<46>ַ<EFBFBD>
|
||||
//else if(*pInput>=0xE0 && *pInput<0xF0)
|
||||
{
|
||||
char high = *pInput;
|
||||
pInput++;
|
||||
char middle = *pInput;
|
||||
pInput++;
|
||||
char low = *pInput;
|
||||
if (((middle & 0xC0) != 0x80) || ((low & 0xC0) != 0x80))
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
*pOutput = (middle << 6) + (low & 0x3F);//ȡ<><C8A1>middle<6C>ĵ<EFBFBD><C4B5><EFBFBD>λ<EFBFBD><CEBB>low<6F>ĵ<EFBFBD>6λ<36><CEBB><EFBFBD><EFBFBD><EFBFBD>ϳ<EFBFBD>unicode<64>ַ<EFBFBD><D6B7>ĵ<EFBFBD>8λ
|
||||
pOutput++;
|
||||
*pOutput = (high << 4) + ((middle >> 2) & 0x0F); //ȡ<><C8A1>high<67>ĵ<EFBFBD><C4B5><EFBFBD>λ<EFBFBD><CEBB>middle<6C><65><EFBFBD>м<EFBFBD><D0BC><EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD><EFBFBD>ϳ<EFBFBD>unicode<64>ַ<EFBFBD><D6B7>ĸ<EFBFBD>8λ
|
||||
}
|
||||
else //<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֽ<EFBFBD><D6BD><EFBFBD><EFBFBD><EFBFBD>UTF8<46>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>д<EFBFBD><D0B4><EFBFBD>
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
pInput ++;//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>utf8<66>ַ<EFBFBD>
|
||||
pOutput ++;
|
||||
outputSize +=2;
|
||||
}
|
||||
//unicode<64>ַ<EFBFBD><D6B7><EFBFBD><EFBFBD><EFBFBD><EFBFBD>棬<EFBFBD><E6A3AC><EFBFBD><EFBFBD><EFBFBD><EFBFBD>\0
|
||||
*pOutput = 0;
|
||||
pOutput++;
|
||||
*pOutput = 0;
|
||||
return outputSize;
|
||||
}
|
||||
|
||||
int main() {
|
||||
// ȷ<><C8B7>Դ<EFBFBD><D4B4><EFBFBD><EFBFBD><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>UTF-8<><38><EFBFBD>뱣<EFBFBD><EBB1A3>
|
||||
char text[] =u8"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
|
||||
//// print_utf8_to_unicode(text);
|
||||
// char outs[1005];
|
||||
// Utf82Unicode(text,outs);
|
||||
printf("str:%04X",text);
|
||||
return 0;
|
||||
}
|
56
my_error/unicode.cpp
Normal file
56
my_error/unicode.cpp
Normal file
@@ -0,0 +1,56 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int utf8ToUnicode(const char* utf8, int* unicode) {
|
||||
unsigned char byte = (unsigned char)utf8[0];
|
||||
int numBytes, codePoint;
|
||||
|
||||
if (byte < 0x80) {
|
||||
// 1<>ֽڱ<D6BD><DAB1>룬ֱ<EBA3AC>ӷ<EFBFBD><D3B7><EFBFBD>
|
||||
numBytes = 1;
|
||||
codePoint = byte;
|
||||
} else if ((byte & 0xE0) == 0xC0) {
|
||||
// 2<>ֽڱ<D6BD><DAB1><EFBFBD>
|
||||
numBytes = 2;
|
||||
codePoint = byte & 0x1F;
|
||||
} else if ((byte & 0xF0) == 0xE0) {
|
||||
// 3<>ֽڱ<D6BD><DAB1><EFBFBD>
|
||||
numBytes = 3;
|
||||
codePoint = byte & 0x0F;
|
||||
} else if ((byte & 0xF8) == 0xF0) {
|
||||
// 4<>ֽڱ<D6BD><DAB1><EFBFBD>
|
||||
numBytes = 4;
|
||||
codePoint = byte & 0x07;
|
||||
} else {
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
return -1;
|
||||
}
|
||||
|
||||
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>µ<EFBFBD><C2B5>ֽ<EFBFBD>
|
||||
for (int i = 1; i < numBytes; ++i) {
|
||||
byte = (unsigned char)utf8[i];
|
||||
if ((byte & 0xC0) != 0x80) {
|
||||
// <20>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>
|
||||
return -1;
|
||||
}
|
||||
codePoint = (codePoint << 6) | (byte & 0x3F);
|
||||
}
|
||||
|
||||
*unicode = codePoint;
|
||||
return numBytes;
|
||||
}
|
||||
|
||||
int main() {
|
||||
char utf8[] = "<EFBFBD><EFBFBD><EFBFBD>ã<EFBFBD><EFBFBD><EFBFBD><EFBFBD>磡";
|
||||
int unicode;
|
||||
|
||||
int numBytes = utf8ToUnicode(utf8, &unicode);
|
||||
if (numBytes == -1) {
|
||||
printf("<EFBFBD>Ƿ<EFBFBD>UTF-8<><38><EFBFBD>룡\n");
|
||||
} else {
|
||||
printf("UTF-8<><38><EFBFBD><EFBFBD>: %s\n", utf8);
|
||||
printf("<EFBFBD><EFBFBD>Ӧ<EFBFBD><EFBFBD>Unicode<EFBFBD><EFBFBD><EFBFBD><EFBFBD>: U+%04X\n", unicode);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Reference in New Issue
Block a user