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

最新文章

  1. ExtJS 4.2 Date组件扩展:添加清除按钮
  2. [k]优雅的css
  3. S2SH CRUD 整合
  4. Learning with Trees
  5. Shapefile文件中的坐标绘制到屏幕时的映射模式设置
  6. ARM Cortex-M instructions
  7. 琐碎-hadoop2.2.0目录结构
  8. git:fatal the current branch master has no upstream branch
  9. 代理下载android4.4源代码
  10. Android MenuItem 设置文本颜色-TextColor设置
  11. King
  12. C#:CsvReader读取.CSV文件并转换成DataTable
  13. 安装Manjaro KDE 18.04
  14. 边学边做,简单的 GraphQL 实例
  15. Linux sed使用方法
  16. Ubuntu18.04安装netstat
  17. JavaScript学习历程02
  18. Hyperledger Fabric v1.1.0安装记录(国内源版)
  19. github不能访问、加载css、js解决办法
  20. On Line Tools

热门文章

  1. eclipse安装Bug检查工具
  2. CF 976F 递增容量最大流
  3. 洛谷P2664 树上游戏——点分治
  4. BZOJ5017 [Snoi2017]炸弹[线段树优化建边+scc缩点+DAG上DP/线性递推]
  5. Force git to overwrite local files on pull 使用pull强制覆盖本地文件 转载自:http://snowdream.blog.51cto.com/3027865/1102441
  6. Excel 中大量图片如何快速导出? 转载自:http://www.zhihu.com/question/20800948
  7. Series和Dataframe分组时使用groupby函数的区别
  8. Map遍历效率 : entrySet &gt; keySet
  9. Java中的集合Queue、LinkedList、PriorityQueue(四)
  10. 享元模式(Flyweight)---结构型