String 经常用法最优算法实现总结 (一)
<pre name="code" class="java"><span style="font-family: Arial, Helvetica, sans-serif;"></pre><p>1. reverse</p><p><pre name="code" class="java"> /**</span>
* @Description: reverse a string.
* @param str the String to reverse, may be null
* @return reversedStr the reversed String, null if null String input
*/
public static String reverse(String str) {
if (isEmpty(str)) {
return str;
} return new StringBuilder(str).reverse().toString();
}
2 . remove
/**
* @Description: Removes all occurrences of a substring from within the source string.
* @param str the source String to search
* @param remove the String to search for and remove
* @return the substring with the string removed if found, null if null String input
*/
public static String remove(String str, String remove) {
if (isEmpty(str) || isEmpty(remove)) {
return str;
} return str.replace(remove, "");
}
3. startsWithIgnoreCase
/**
*
* @Title: startsWithIgnoreCase
* @Description: check if a string starts with a specified prefix.
* @param str input value
* @param prefix prefix value
* @return true if the string starts with the prefix, case insensitive, or both null, blank
*/
public static boolean startsWithIgnoreCase(String str, String prefix) {
if (str == null || prefix == null) {
return (str == null && prefix == null);
} if (prefix.length() > str.length()) {
return false;
} return str.toUpperCase().startsWith(prefix.toUpperCase());
}
4. isAllAlphas
/**
* whether value does not contain number(s).
*
* @Title: isAllAlphas
* @param value the source to be handled
* @return boolean
*/
public static boolean isAllAlphas(String value) {
// if input parameter is null, just return
if (value == null) {
return false;
} for (int i = 0; i < value.length(); i++) {
if (!(Character.isLetter(value.charAt(i)))) {
return false;
}
} return true;
}
5. isNumeric
/**
* check if the CharSequence contains only unicode digits.
*
* @Title: isNumber
* @param str input str
* @return true or false
*/
public static boolean isNumeric(String str) {
// if input parameter is null, just return false
if (isEmpty(str)) {
return false;
} for (int i = 0; i < str.length(); i++) {
// if there is a alpha, return false
if (!Character.isDigit(str.charAt(i))) {
return false;
}
} return true;
}
String 经常用法最优算法实现总结 (一)的更多相关文章
- String 经常用法最优算法实现总结 (二)
1. String getOrderedString(boolean isDuplicated, String - str) 说明: Orders all characters in the inpu ...
- C#中string.format用法详解
C#中string.format用法详解 本文实例总结了C#中string.format用法.分享给大家供大家参考.具体分析如下: String.Format 方法的几种定义: String.Form ...
- String.format()用法
package junit.test; import java.util.Date; import java.util.Locale; import org.junit.Test; pub ...
- java中String的用法
String的用法很活跃,也用到的很多.可以根据自己的需要查询API.这里只有concat和substring,indexof的用法 class TestString { public static ...
- C#中string.Format 用法详解
这篇文章主要介绍了C#中string.format用法,以实例形式较为详细的讲述了string.format格式化的各种用法,非常具有实用价值,需要的朋友可以参考下 本文实例总结了C#中string. ...
- Oracle中dbms_random.string 的用法
转载:https://blog.csdn.net/simonchi/article/details/8657787 DBMS_RANDOM.STRING(var1,var2) 这个函数有两个参数 va ...
- 关于java中String的用法
在java 中String存在许多的基本函数,接下来了解一下这些函数的基本用法 String.equals用法(这个用法比较难) String类中的equals()方法: public boolean ...
- java成神之——java中string的用法
java中String的用法 String基本用法 String分割 String拼接 String截取 String换行符和format格式化 String反转字符串和去除空白字符 String获取 ...
- string.join用法
C# String.Join用法 String.Join(String, String[]) 在指定 String 数组的每个元素之间串联指定的分隔符 String,从而产生单个串联的字符串 例如: ...
随机推荐
- B3680 吊打xxx 物理???
看到一道很有意思的题,这个题简直有毒,是一道物理题...好像得用模拟退火...但显然我太弱了不会模拟退火,只能用正交分解暴力... 每次沿着力的方向走一定的距离,假如转头了,则走的步长就减小一点. 不 ...
- Python 33(1) UDP协议 数据报协议 socketsever模块
一:基于UDP协议通信的套接字 基于UDP协议 只要是套接字,在开发的过程中一定要有服务端和客户端. UDP协议说的就是数据报协议,也就是说,基于UDP协议来发数据,每发一个数据,都是带有报头的数据 ...
- [转]rdlc报表中表达式的使用--switch和IIF范例
本文转自:http://hi.baidu.com/oypx1234/item/5b35dec4e03a3ad697445266 =Switch( Fields!MLWHLO.Value = " ...
- 汇编程序10:计算长度为C字节的数据和
assume cs:code code segment mov ax,0ffffh //起始段地址 mov ds,ax mov bx,0 //偏移变量 mov dx,0 //保存结果 mov cx,1 ...
- HDU 4474 Yet Another Multiple Problem BFS
题意:求m的倍数中不包含一些数码的最小倍数数码是多少.比如15 ,不包含0 1 3,答案是45. BFS过程:用b[]记录可用的数码.设一棵树,树根为-1.树根的孩子是所有可用的数码,孩子的孩子也是 ...
- HTTPS的中那些加密算法
密码学在计算机科学中使用非常广泛,HTTPS就是建立在密码学基础之上的一种安全的通信协议.HTTPS早在1994年由网景公司首次提出,而如今在众多互联网厂商的推广之下HTTPS已经被广泛使用在各种大小 ...
- ThinkPHP3.2.3对数据的添、删、改、查(CURD)
对数据的添加: public function form() { parent::common(); $obj = D('Leave'); if (IS_POST) { $data = I('post ...
- 溢出文本省略号的js实现
function ellipsis(element) { var limitWidth = element.clientWidth; var temp = element.cloneNode(true ...
- bootstrap模态框和select2合用时input无法获取焦点(转)
在bootstrap的模态框里使用select2插件,会导致select2里的input输入框没有办法获得焦点,没有办法输入. 解决方法: 1. 把页面中的 tabindex="-1&qu ...
- android学习-第二讲(修改项目名称和图标,log,过滤器)
一.在app/src/main/res下有 AndroidManifest.xml打开,打开后如下图1 二.日志工具log log.v() log.d() log.i() log.w() lo ...