Lifyray笑傲江湖之API总结TextUtil
package liferay; /**
*
*/ import java.text.DecimalFormat;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern; /**
* @author Ivan
*
*/
public class TextUtil { private static Pattern N = Pattern.compile("\n");
private static Pattern R = Pattern.compile("\r");
private static Pattern RN = Pattern.compile("\r\n");
private static Pattern NR = Pattern.compile("\n\r");
private final static String BR = "<br/>"; private static NumberFormat decimalFormat = DecimalFormat
.getNumberInstance(); public static String doubleToText(double number) {
String txt = doubleToText(number, );
return txt;
} public static String doubleToText(double number, int digit) {
String txt = "";
if (number > ) {
decimalFormat.setMaximumFractionDigits(digit);
txt = decimalFormat.format(number);
}
return txt;
} public static String doubleToText2(double number, int digit) {
String txt = "";
if (number > ) {
DecimalFormat decimalFormat2 = new DecimalFormat();
decimalFormat2.setGroupingSize();
decimalFormat2.setMaximumFractionDigits(digit);
txt = decimalFormat2.format(number);
}
return txt;
} public static String doubleToText(double number, String format) {
if (format.equals("")) {
format = "#,##0.00";
} String txt = "";
if (number > ) {
DecimalFormat decimalFormat = new DecimalFormat(format);
txt = decimalFormat.format(number);
}
return txt;
} public static String textToHtml(String txt) {
Matcher m = RN.matcher(txt);
txt = m.replaceAll(BR);
m = NR.matcher(txt);
txt = m.replaceAll(BR);
m = N.matcher(txt);
txt = m.replaceAll(BR);
m = R.matcher(txt);
txt = m.replaceAll(BR);
return txt;
} public static void main(String[] args) {
// long longDuration = new Date().getTime() - 46450000;
// longDuration = new Date().getTime() - longDuration;
// double doubleDuration = longDuration;
// doubleDuration = doubleDuration / 86400000;
// System.out.println(doubleDuration);
// System.out.println(doubleToText(doubleDuration)); String sql = getRandomString();
System.out.println(sql); } public static String doSubAssignLength(String str, int length) {
String commtents = null;
if (str.length() > length) {
commtents = str.substring(, length - ) + "...";
} else {
commtents = str;
}
return commtents;
} public static String doSubString(String str) {
String commtents = null;
if (str.length() > ) {
commtents = str.substring(, ) + "...";
} else {
commtents = str;
}
return commtents;
} public static String getURL(String layoutId, String url) {
StringBuffer buffer = new StringBuffer();
buffer.append(url);
if (layoutId != null && !"".equals(layoutId)) {
int start = url.lastIndexOf("/");
int end = url.indexOf("?");
buffer.replace(start, end, layoutId);
}
return buffer.toString();
} public static String toUpperCase(String tableName) {
String prefix = tableName.substring(, ).toUpperCase();
String results = prefix + tableName.substring();
return results;
} public static String getRandomString(int length) {
char[] charArray = new char[length];
for (int i = ; i < length; i++) {
Random r = new Random();
int n = r.nextInt();
while (n < || (n > && n < ) || (n > && n < )
|| n > ) {// (!((n>=48 && n<=57) || (n>=65 && n<=90)
// && (n>=97 && n<=122))){
n = r.nextInt();
}
charArray[i] = (char) n;
}
return String.valueOf(charArray);
} public static String convertFileSize(long filesize) {
String strUnit = "Bytes";
String strAfterComma = "";
int intDivisor = ;
if (filesize >= * ) {
strUnit = " MB";
intDivisor = * ;
} else if (filesize >= ) {
strUnit = " KB";
intDivisor = ;
}
if (intDivisor == )
return filesize + " " + strUnit; strAfterComma = "" + * (filesize % intDivisor) / intDivisor;
if (strAfterComma == "")
strAfterComma = ".0"; return filesize / intDivisor + "." + strAfterComma + " " + strUnit; } }
Lifyray笑傲江湖之API总结TextUtil的更多相关文章
- 干货来袭-整套完整安全的API接口解决方案
在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...
- 12306官方火车票Api接口
2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...
- 几个有趣的WEB设备API(二)
浏览器和设备之间还有很多有趣的接口, 1.屏幕朝向接口 浏览器有两种方法来监听屏幕朝向,看是横屏还是竖屏. (1)使用css媒体查询的方法 /* 竖屏 */ @media screen and (or ...
- html5 canvas常用api总结(三)--图像变换API
canvas的图像变换api,可以帮助我们更加方便的绘画出一些酷炫的效果,也可以用来制作动画.接下来将总结一下canvas的变换方法,文末有一个例子来更加深刻的了解和利用这几个api. 1.画布旋转a ...
- JavaScript 对数据处理的5个API
JavaScript对数据处理包括向上取整.向下取整.四舍五入.固定精度和固定长度5种方式,分别对应ceil,floor,round,toFixed,toPrecision等5个API,本文将对这5个 ...
- ES5对Array增强的9个API
为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...
- javascript的api设计原则
前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博文同时也参考了其他一些文章,相关地址会在后面贴出来.很难做到 ...
- 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino
大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...
- 在一个空ASP.NET Web项目上创建一个ASP.NET Web API 2.0应用
由于ASP.NET Web API具有与ASP.NET MVC类似的编程方式,再加上目前市面上专门介绍ASP.NET Web API 的书籍少之又少(我们看到的相关内容往往是某本介绍ASP.NET M ...
随机推荐
- 用mongoose实现mongodb增删改查
//用户 var mongoose = require("mongoose"), setting = require("./setting"); //配置连接数 ...
- yii---解决post请求出现500错误
在使用yii框架的时候,在发送数据请求的时候,POST请求会出现500错误,这是因为yii2开启了防御csrf的攻击机制,可去先去掉,在控制器里去掉:public $enableCsrfValidat ...
- 编程(Linux、windows)常见命令
1.history | grep start 可以查看该linux上输入过的包含start的所有命令 2. for /r %i in (*.lastUpdated) do del %i 在windo ...
- python3中如何区分一个函数和方法
一般情况下,单独写一个def func():表示一个函数,如果写在类里面是一个方法.但是不完全准确. class Foo(object): def fetch(self): pass print(Fo ...
- OpenCV Cut Image via ROI 根据兴趣区域剪裁图片
我们在使用OpenCV时,有时候需要对现有图片剪裁,比如只需要一个小窗口中的内容,那么我们可以通过OpenCV的兴趣区域 Region of Interest (ROI) 来很轻易的实现,操作也很简单 ...
- vs code 搭建flutter运行环境(mac)
之前开发过hybrid app,用的是webview渲染,由于webview的体验会没有原生的体验好,所以对跨端原生开发燃起了学习的兴趣,在react-native和flutter之间纠结, 看了网上 ...
- jQuery ajax的前台代码编写
jQuery ajax的前台代码: <script type="text/javascript" src="/include/jquery/jquery-1.1.3 ...
- Ubuntu 16.04 ORB_SLAM2+ROS+usb_cam+AR
Ubuntu 16.04 ORB_SLAM2+ROS+usb_cam+AR 参考博文:http://blog.csdn.net/u79501/article/details/68942174 http ...
- TensorFlow指定GPU使用及监控GPU占用情况
查看机器上GPU情况 命令: nvidia-smi 功能:显示机器上gpu的情况 命令: nvidia-smi -l 功能:定时更新显示机器上gpu的情况 命令:watch -n 3 nvidia-s ...
- Python:字符串处理函数
split() / join() 拆分和组合 #split() 通过指定分隔符对字符串进行切片(拆分),默认空格符 lan = "python ruby c c++ swift" ...