public static String StringToUnicode(String inStr) {
char[] myBuffer = inStr.toCharArray();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < inStr.length(); i++) {
UnicodeBlock ub = UnicodeBlock.of(myBuffer[i]);
if(ub == UnicodeBlock.BASIC_LATIN){
sb.append(myBuffer[i]);
}else if(ub == UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS){
int j = (int) myBuffer[i] - 65248;
sb.append((char)j);
}else{
char s = (char) myBuffer[i];
String hexS = Integer.toHexString(s);
String unicode = "\\u"+hexS;
sb.append(unicode.toLowerCase());
}
}
return sb.toString();
}
public static String unicodeToString(String theString) {
char aChar;
int len = theString.length();
StringBuffer outBuffer = new StringBuffer(len);
for (int x = 0; x < len;) {
aChar = theString.charAt(x++);
if (aChar == '\\') {
aChar = theString.charAt(x++);
if (aChar == 'u') {
int value = 0;
for (int i = 0; i < 4; i++) {
aChar = theString.charAt(x++);
switch (aChar) {
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
case '8':
case '9':
value = (value << 4) + aChar - '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
value = (value << 4) + 10 + aChar - 'a';
break;
case 'A':
case 'B':
case 'C':
case 'D':
case 'E':
case 'F':
value = (value << 4) + 10 + aChar - 'A';
break;
default:
throw new IllegalArgumentException(
"Malformed \\uxxxx encoding.");
}
}
outBuffer.append((char) value);
} else {
if (aChar == 't')
aChar = '\t';
else if (aChar == 'r')
aChar = '\r';
else if (aChar == 'n')
aChar = '\n';
else if (aChar == 'f')
aChar = '\f';
outBuffer.append(aChar);
}
} else
outBuffer.append(aChar);
}
return outBuffer.toString();
}
分享到:
相关推荐
在我们的例子中,`String`类已经实现了`Comparable<String>`接口,因此我们可以直接对`List<String>`进行排序。然而,`Collections.sort()`是基于字符串的自然顺序进行排序,即按照Unicode字符的编码顺序比较字符串...
在C++中,可以使用`std::wstring_convert`和`std::codecvt_utf8_utf16`等库函数来完成这个任务,但需要注意的是,这些函数在C++17后已被弃用,推荐使用`std::string_view`和第三方库如`boost`。 `字符编码.docx`...
UniString.zip<br>Class to manipulate UNICODE string on Window 95/98.(6KB)<END><br>11,faststring.zip<br>Fast and efficient CString replacement(63KB)<END><br>12,StdString.zip<br>CString like class using...
<xsl:value-of select="string(314)"/> <!-- 输出:"314" --> ``` 8. `fn:codepoints-to-string(int,int,...)`:根据一系列Unicode代码点生成字符串。 示例: ```xml <xsl:value-of select="codepoints-to-...
String类型<br>11.4.1. CHAR和VARCHAR类型<br>11.4.2. BINARY和VARBINARY类型<br>11.4.3. BLOB和TEXT类型<br>11.4.4. ENUM类型<br>11.4.5. SET类型<br>11.5. 列类型存储需求<br>11.6. 选择正确的列类型<br>11.7. ...
<br>Browser Prototype jQuery Mootools Ext Dojo <br>IE 6 1476ms 661ms 1238ms 672ms 738ms <br>Firefox 2 219ms 567ms 220ms 951ms 440ms <... <br><br><br>更新项目<br><br><br>New Selectors<br>Unicode Selectors...
#include <string> std::string numberToChar(int num) { std::string result; while (num > 0) { char c = static_cast<char>('A' + (num - 1) % 26); result = c + result; num -= 1 + (num - 1) / 26; } ...
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> <init-param> ...
-search <pattern> get the start offset by the pattern: e.g. PK\x03\x04 -soff <offset> fix the match offset after searching (Default: 0) -off <offset> convert the input file from the offset (Default...
<string name="app_name">我的应用(中文版)</string> <!-- 其他中文字符串 --> </resources> <!-- values-en/strings.xml --> <resources> <string name="app_name">My App (English)</string> <!-- 其他英文...
5. 使用宽字符版本的C++标准库,例如:string -> wstring,fstream -> wfstream,ofstream -> wofstream。 6. 宽字符版本的英文字符可以直接与整型值进行比较,如 `s[0] == 'A'`。 7. 如果需要与第三方库的ANSI接口...
<param-name>encoding</param-name> <param-value>GBK</param-value> </init-param> </filter> <filter-mapping> <filter-name>Set Character Encoding</filter-name> <url-pattern>/*</url-pattern> </filter-...
Map<String, Object> parameters = new HashMap<>(); parameters.put("dataList", dataList); JRBeanCollectionDataSource dataSource = new JRBeanCollectionDataSource(dataList); // 渲染报表 JasperPrint ...
String^ value = safe_cast<String^>(cell->Value2); // 读取单元格值 ``` 7. **保存并关闭工作簿和应用**: 完成操作后,记得保存并关闭工作簿,然后释放Excel应用对象: ```cpp workbook->Save(); workbook...
<p>Unicode String: <%= unicodeString %></p> ``` 这里使用了Unicode转义序列`\uXXXX`来表示汉字,其中`XXXX`是四个十六进制数字,表示该字符的Unicode码点。 #### 7. 设置页面编码为GB2312 在处理中文时,除了...
UNICODE_STRING deviceName; PDEVICE_EXTENSION pdx; PDEVICE_OBJECT filterDeviceObject; PDEVICE_OBJECT targetDevice; fileOjbect=NULL; RtlInitUnicodeString(&deviceName;,L"\\Device\\KeyBoardClass0"); ...
3. **字符串宏**:字符串常量应使用_T()宏,如"string" -> _T("string")。 4. **函数替换**:替换C库中的字符串操作函数,如strlen -> _tcslen,strcmp -> _tcscmp。同样,涉及字符串与数字转换的函数也要替换,如...
// Add a Unicode font (uses UTF-8) $pdf->AddFont('Yahei','','Monaco_Yahei.ttf',true); $pdf->SetFont('Yahei','',8); // Load a UTF-8 string from a file and print it //$txt = file_get_contents('...
本篇文章将深入探讨如何在`MemoryStream`, `TList<String>` 和 `stringstream`(即`TStringStream`)之间进行转换,以实现不同数据结构之间的高效数据交换。 首先,让我们了解这三个对象的基本概念: 1. **...