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. How arduino IDE works?

    test.ino void setup() { pinMode(,OUTPUT); } void loop() { digitalWrite(,HIGH); delay(); digitalWrite ...

  2. 【CF603E】Pastoral Oddities cdq分治+并查集

    [CF603E]Pastoral Oddities 题意:有n个点,依次加入m条边权为$l_i$的无向边,每次加入后询问:当前图是否存在一个生成子图,满足所有点的度数都是奇数.如果有,输出这个生成子图 ...

  3. Android 获取View中的组件

    可以把这个view强转成ViewGroup对象,再通过getChildAt(0),getChildAt(1) 获取之后AddView可能会报错:IllegalStateException: The s ...

  4. Unity3D NGUI 二 NGUI Button怎样接受用户点击并调用函数,具体方法名称是什么

    a.直接监听事件 把下面脚本直接绑定在按钮上,当按钮点击时就可以监听到,这种方法不太好很不灵活. void OnClick(){ Debug.Log("Button is Click!!!& ...

  5. Django---简单from表单提交

    表单提交可能会报错,注意一行代码就可以解决: 简单配置路由: 简单表单提交: <form action="/index/" method="post"&g ...

  6. 【转载】51单片机data,bdata,idata,xdata使用注意事项

    "51单片机编程在不同内存空间data xdata bdata定义变量的注意事项": 关键词:51 单片机 编程 不同 内存空间 data xdatabdata 定义 变量 注意事 ...

  7. 2018-2019-2 20165330《网络对抗技术》Exp2 后门原理与实践

    目录 基础问题 相关知识 实验内容 实验步骤 实验过程中遇到的问题 实验总结与体会 实验内容 使用netcat获取主机操作Shell,cron启动 使用socat获取主机操作Shell, 任务计划启动 ...

  8. HDU 3642 - Get The Treasury - [加强版扫描线+线段树]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3642 Time Limit: 10000/5000 MS (Java/Others) Memory L ...

  9. POJ 2398 - Toy Storage - [计算几何基础题][同POJ2318]

    题目链接:http://poj.org/problem?id=2398 Time Limit: 1000MS Memory Limit: 65536K Description Mom and dad ...

  10. NEFU 118 - n!后面有多少个0 & NEFU 119 - 组合素数 - [n!的素因子分解]

    首先给出一个性质: n!的素因子分解中的素数p的幂为:[ n / p ] + [ n / p² ] + [ n / p³ ] + …… 举例证明: 例如我们有10!,我们要求它的素因子分解中2的幂: ...