GBK格式字符串右补空格
public class Test2 {
public static void main(String[] s) throws IOException {
List<User> list = new ArrayList<User>();
String aa = "";
try {
System.out.println(formatStr("汪333,3", 20));
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 补充空格
* 参数(str字符串,字段的长度)
*/
public static String formatStr(String str, int length) throws Exception {
if (str == null) {
return null;
}
int strLen = str.getBytes("GBK").length; //空格的长度 = 20 - 字段的长度(GBK)。
if (strLen == length) {
return str;
} else if (strLen < length) {
int temp = length - strLen;
String tem = "";
for (int i = 0; i < temp; i++) {
tem = tem + " ";
}
return str + tem;
}else{
return str.substring(0,length);
}
}
转载:https://blog.csdn.net/changNet/article/details/8674348?locationNum=13&fps=1
最新文章
- ExtJS 4.2 Date组件扩展:添加清除按钮
- [k]优雅的css
- S2SH CRUD 整合
- Learning with Trees
- Shapefile文件中的坐标绘制到屏幕时的映射模式设置
- ARM Cortex-M instructions
- 琐碎-hadoop2.2.0目录结构
- git:fatal the current branch master has no upstream branch
- 代理下载android4.4源代码
- Android MenuItem 设置文本颜色-TextColor设置
- King
- C#:CsvReader读取.CSV文件并转换成DataTable
- 安装Manjaro KDE 18.04
- 边学边做,简单的 GraphQL 实例
- Linux sed使用方法
- Ubuntu18.04安装netstat
- JavaScript学习历程02
- Hyperledger Fabric v1.1.0安装记录(国内源版)
- github不能访问、加载css、js解决办法
- On Line Tools
热门文章
- eclipse安装Bug检查工具
- CF 976F 递增容量最大流
- 洛谷P2664 树上游戏——点分治
- BZOJ5017 [Snoi2017]炸弹[线段树优化建边+scc缩点+DAG上DP/线性递推]
- Force git to overwrite local files on pull 使用pull强制覆盖本地文件 转载自:http://snowdream.blog.51cto.com/3027865/1102441
- Excel 中大量图片如何快速导出? 转载自:http://www.zhihu.com/question/20800948
- Series和Dataframe分组时使用groupby函数的区别
- Map遍历效率 : entrySet >; keySet
- Java中的集合Queue、LinkedList、PriorityQueue(四)
- 享元模式(Flyweight)---结构型