获得指定长度字符串,不足位右补空格

	/**
	 * 生成指定长度字符串,不足位右补空格
	 * @param str
	 * @param length
	 * @return
	 */
	private static String formatStr(String str, int length) {
		int strLen;
		if (str == null) {
			strLen = 0;
		}else{
			strLen= str.length();
		}
		
		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/weixin_39412250/article/details/80563582

猜你喜欢

转载自blog.csdn.net/fendou_0123456789/article/details/81983610
今日推荐