fullToHalf property
String
get
fullToHalf
字符串全角转半角
Implementation
String get fullToHalf {
if (this == null || this!.isEmpty) {
return "";
}
final StringBuffer buffer = StringBuffer();
for (int i = 0; i < this!.length; i++) {
final int code = this!.codeUnitAt(i);
// 全角空格转换为半角空格
if (code == 12288) {
buffer.writeCharCode(32);
}
// 全角字符范围:65281 到 65374
else if (code >= 65281 && code <= 65374) {
buffer.writeCharCode(code - 65248);
}
// 其他字符保持不变
else {
buffer.writeCharCode(code);
}
}
return buffer.toString();
}