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的更多相关文章

  1. 干货来袭-整套完整安全的API接口解决方案

    在各种手机APP泛滥的现在,背后都有同样泛滥的API接口在支撑,其中鱼龙混杂,直接裸奔的WEB API大量存在,安全性令人堪优 在以前WEB API概念没有很普及的时候,都采用自已定义的接口和结构,对 ...

  2. 12306官方火车票Api接口

    2017,现在已进入春运期间,真的是一票难求,深有体会.各种购票抢票软件应运而生,也有购买加速包提高抢票几率,可以理解为变相的黄牛.对于技术人员,虽然写一个抢票软件还是比较难的,但是还是简单看看123 ...

  3. 几个有趣的WEB设备API(二)

    浏览器和设备之间还有很多有趣的接口, 1.屏幕朝向接口 浏览器有两种方法来监听屏幕朝向,看是横屏还是竖屏. (1)使用css媒体查询的方法 /* 竖屏 */ @media screen and (or ...

  4. html5 canvas常用api总结(三)--图像变换API

    canvas的图像变换api,可以帮助我们更加方便的绘画出一些酷炫的效果,也可以用来制作动画.接下来将总结一下canvas的变换方法,文末有一个例子来更加深刻的了解和利用这几个api. 1.画布旋转a ...

  5. JavaScript 对数据处理的5个API

    JavaScript对数据处理包括向上取整.向下取整.四舍五入.固定精度和固定长度5种方式,分别对应ceil,floor,round,toFixed,toPrecision等5个API,本文将对这5个 ...

  6. ES5对Array增强的9个API

    为了更方便的对Array进行操作,ES5规范在Array的原型上新增了9个方法,分别是forEach.filter.map.reduce.reduceRight.some.every.indexOf ...

  7. javascript的api设计原则

    前言 本篇博文来自一次公司内部的前端分享,从多个方面讨论了在设计接口时遵循的原则,总共包含了七个大块.系卤煮自己总结的一些经验和教训.本篇博文同时也参考了其他一些文章,相关地址会在后面贴出来.很难做到 ...

  8. 一百元的智能家居——Asp.Net Mvc Api+讯飞语音+Android+Arduino

    大半夜的,先说些废话提提神 如今智能家居已经不再停留在概念阶段,高大上的科技公司都已经推出了自己的部分或全套的智能家居解决方案,不过就目前的现状而言,大多还停留在展厅阶段,还没有广泛的推广起来,有人说 ...

  9. 在一个空ASP.NET Web项目上创建一个ASP.NET Web API 2.0应用

    由于ASP.NET Web API具有与ASP.NET MVC类似的编程方式,再加上目前市面上专门介绍ASP.NET Web API 的书籍少之又少(我们看到的相关内容往往是某本介绍ASP.NET M ...

随机推荐

  1. 去除select边框和三角-----appearance:none

    今天发现一个比较有意思的属性,appearance:none 可能有朋友不认识,但是有一个标签你肯定认识:select. 这个标签的样式是这样的: 一般情况下,我们所使用的border:0; 去除边框 ...

  2. CreateTimerQueueTimer在DllMain中调用导致的loader lock

    开发一个COM组件在Windows 7上注册成功,但是Windows XP SP3版本却导致regsvr32.exe进程挂起.用WinDbg查看发现提示: Break- seconds... WARN ...

  3. 安卓使用Root权限实现后台模拟全局按键、触屏事件方法(类似按键精灵)

    继续在网上搜索安卓按键模拟(其实那时都不知道用什么关键字好了,能想到的关键字都用遍了,但是搜索出来的结果,都是之前提到的那几个依赖源码环境和系统权限的方案).发现有很多介绍ADB调试,向手机发送按键事 ...

  4. Memcached概念、作用、运行原理、特性、不足简单梳理(1)

    大家可能对memcached这种产品早有了解,或者已经应用在自己的网站中了,但是也有一些朋友从来都没有听说过或者使用过.这都没什么关系,本文旨在从各个角度综合的介绍这种产品,尽量深入浅出,如果能对您现 ...

  5. Linux下常用命令wget的使用技巧

    Linux下wget是一个下载文件的工具,它用在命令行下.对于Linux用户是必不可少的工具,尤其对于网络管理员 经常要下载一些软件或从远程服务器恢复备份到本地服务器.如果我们使用虚拟主机,处理这样的 ...

  6. Spring Cloud Eureka 高可用注册中心

    参考:<<spring cloud 微服务实战>> 在微服务架构这样的分布式环境中,各个组件需要进行高可用部署. Eureka Server 高可用实际上就是将自己作为服务向其 ...

  7. Spring Boot 利用插件构造QueryDSL语句时报错:You need to run build with JDK or have tools.jar on the classpath.If this occur....

    You need to run build with JDK or have tools.jar on the classpath.If this occures during eclipse bui ...

  8. 8.26 js

    2018-8-26 20:35:53 这两天周末,一直在看苏东坡传! 明天正常学python 用心学!

  9. Qt Package Project 打包发布程序

    在Qt项目开发完成后,我们想将项目打包发布成一个可执行文件,需要做如下步骤: 首先,将项目中的release文件中的可执行文件拷到一个新建的文件夹中,例如project.exe,用Qt自带的生成必备的 ...

  10. 为什么 Redis 重启后没有正确恢复之前的内存数据

    安装 Redis 后,默认配置下启动会得到如下日志: [] Sep ::! Background save may fail under low memory condition. To fix th ...