mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
获取带圈字母 /封闭式字母 ,从a-z or A-Z
This commit is contained in:
parent
739af1befe
commit
80e54e512f
@ -1,5 +1,7 @@
|
||||
package cn.hutool.core.text;
|
||||
|
||||
import java.math.BigInteger;
|
||||
|
||||
/**
|
||||
* 符号工具类
|
||||
* @author dazer & neusoft
|
||||
@ -51,18 +53,48 @@ public class SpecialSymbolUtil {
|
||||
* @param number 十进制数字,从1、-->10、11--->20
|
||||
* @return ①②③④⑤⑥⑦⑧⑩⑪⑫⑬⑭⑮⑯⑰⑱⑲⑳
|
||||
*/
|
||||
public static String enclosedAlphanumericsCircleByInt(int number) {
|
||||
public static String enclosedNumericsByInt(int number) {
|
||||
if (number <= 0 || number > 20) {
|
||||
throw new IllegalArgumentException("number取值范围是[1-20]的正整数,包含1和20");
|
||||
}
|
||||
String start = "①";
|
||||
String unicodeStart = UnicodeUtil.toUnicode(start).substring(UNICODE_START_CHAR.length(),
|
||||
UnicodeUtil.toUnicode(start).length() - 1);
|
||||
String beginHex = unicodeStart.substring(0, 2); // begin: U+246x的24
|
||||
String middleHex = number >= 17 ? "7" : "6"; // U+246x的6
|
||||
String endHex = Integer.toHexString(number >= 17 ? number - 17 : number - 1); // A
|
||||
// begin: U+246x的24
|
||||
String beginHex = unicodeStart.substring(0, 2);
|
||||
// U+246x的6
|
||||
String middleHex = number >= 17 ? "7" : "6";
|
||||
// A
|
||||
String endHex = Integer.toHexString(number >= 17 ? number - 17 : number - 1);
|
||||
// U + 24 + 60
|
||||
String unicodeStr = UNICODE_START_CHAR + beginHex + middleHex + endHex;
|
||||
return UnicodeUtil.toString(unicodeStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取带圈字母 /封闭式字母 ,从a-z or A-Z
|
||||
* 根据字符 获取 Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ
|
||||
* <code>
|
||||
* System.out.println(encloseAlphabetByChar( 'A'));
|
||||
* System.out.println(encloseAlphabetByChar( 'a'));
|
||||
* System.out.println(encloseAlphabetByChar( 'z'));
|
||||
* System.out.println(encloseAlphabetByChar( 'Z'))
|
||||
* </code>
|
||||
* @author dazer
|
||||
* @param letter 字母,不区分大小写,'a'、'b'、'c'、'd'...'x'、'y'、'z'; 'A'、'B'...'Z'
|
||||
* @date 2021/3/26 18:10
|
||||
*/
|
||||
public static String encloseAlphabetByChar(char letter) {
|
||||
if (!(letter >= 'a' && letter <= 'z' || letter >= 'A' && letter <= 'Z')) {
|
||||
throw new IllegalArgumentException("number取值范围是[a-z]、[A-Z]的字符");
|
||||
}
|
||||
// \u24b6
|
||||
String start = "Ⓐ";
|
||||
String hexStr = UnicodeUtil.toUnicode(start).substring(UNICODE_START_CHAR.length());
|
||||
int difference = letter >= 'a' && letter <= 'z' ? (letter - (int)'a') : (letter - (int)'A');
|
||||
String hex = new BigInteger(hexStr, 16).add(new BigInteger(String.valueOf(difference), 10)).toString(16);
|
||||
//
|
||||
String unicodeStr = UNICODE_START_CHAR + hex;
|
||||
return UnicodeUtil.toString(unicodeStr);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user