java.lang.String.trim(), 不仅仅去掉空格
public String trim() {
int len = value.length;
int st = 0;
char[] val = value; /* avoid getfield opcode */
while ((st < len) && (val[st] <= ' ')) {
st++;
}
while ((st < len) && (val[len - 1] <= ' ')) {
len--;
}
return ((st > 0) || (len < value.length)) ? substring(st, len) : this;
}
Returns a string whose value is this string, with any leading and trailing whitespace removed.
If this String object represents an empty character sequence, or the first and last characters of character sequence represented by this String object both have codes greater than '\u005Cu0020' (the space character), then a reference to this String object is returned.
Otherwise, if there is no character with a code greater than '\u005Cu0020' in the string, then a String object representing an empty string is returned.
Otherwise, let k be the index of the first character in the string whose code is greater than '\u005Cu0020', and let m be the index of the last character in the string whose code is greater than '\u005Cu0020'. A String object is returned, representing the substring of this string that begins with the character at index k and ends with the character at index m-that is, the result of this.substring(k, m + 1).
This method may be used to trim whitespace (as defined above) from the beginning and end of a string.
Returns:
A string whose value is this string, with any leading and trailing white space removed, or this string if it has no leading or trailing white space.

java.lang.String.trim(), 不仅仅去掉空格的更多相关文章
- Java笔记之java.lang.String#trim
String的trim()方法是使用频率频率很高的一个方法,直到不久前我不确定trim去除两端的空白符时对换行符是怎么处理的点进去看了下源码的实现,才发现String#trim的实现跟我想像的完全不一 ...
- 117、Java中String类之去掉左右空格
01.代码如下: package TIANPAN; /** * 此处为文档注释 * * @author 田攀 微信382477247 */ public class TestDemo { public ...
- java.lang.String
1.String 是一个类,广泛应用于 Java 程序中,相当于一系列的字符串.在 Java 语言中 strings are objects.创建一个 strings 最直接的方式是 String g ...
- java:常用类(包装类,equals和==的比较,Date,java.lang.String中常用方法,枚举enum)
*包装类: 将基本类型封装成类,其中包含属性和方法以方便对象操作. *byte---->Byte *short--->Short *long--->Long *float---> ...
- javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String
javax.el.PropertyNotFoundException: Property 'name' not found on type java.lang.String javax.el.Bean ...
- groovy --不注意的小错误(java.lang.String.positive() is applicable)
sql 语句拼接报错: No signature of method: java.lang.String.positive() is applicable for argument types: () ...
- java中string.trim()函数的使用
java中string.trim()函数的的作用是去掉字符串开头和结尾的空格,防止不必要的空格导致的错误. public static void main(String arg[]){ String ...
- java.lang.String 类源码解读
String类定义实现了java.io.Serializable, Comparable<String>, CharSequence 三个接口:并且为final修饰. public fin ...
- java.lang.String & java.lang.StringBuilder
java.lang.String & java.lang.StringBuilder String 成员方法 作用 public charAr(int index) 返回给定位置的代码单元 p ...
随机推荐
- qml 与C++交互
最近一直在研究qml 怎么与C++交互,今天在网上看到一段代码忽然想明白了,哦!!!我在QT还只是一个小白,嘿嘿 首先在我们定义了CPP文件起名:比如:util.cpp,baidumusic.cpp ...
- TableviewCell嵌套TextView自动换行
TableviewCell嵌套TextView自动换行 欢迎到github上去下载源码Demo, github链接:https://github.com/mengzhihun6 效果图:
- Linux系统在启动过程中启动级别发生错误的解决办法
一.系统启动级别一共有六个: 0:系统停机模式,系统不可以正常启动 1:单用户模式, root权限,用于系统的维护,禁止远程登陆 2:多用户模式,没有NFS网络支持 3:完整的多用户文本模式,有NFS ...
- windows7 下安装python3.6开发环境
所有的软件都放在百度云盘里: 链接: https://pan.baidu.com/s/1rux8sDK9thhbZ1qjwQg6kA 密码: iq4c 1. 安装python3.6.5 安装的时候要把 ...
- (转)MapReduce Design Patterns(chapter 2 (part 3))(四)
Inverted Index Summarizations Pattern Description 反向索引模式在MapReduce分析中经常作为一个例子.我们将会讨论我们要创建的term跟标识符之间 ...
- python3之环境搭建以及基础语法
早些时候,有一段时间吧,为了想免费下载网易云的收费音乐,也是翻了下python的教程的,语法方面没细致地去看,跟java.php.javascript这些都大同小异,也是面向对象的.那么,近期准备快速 ...
- Android版本的"Wannacry"文件加密病毒样本分析(附带锁机)
一.前言 之前一个Wannacry病毒样本在PC端肆意了很久,就是RSA加密文件,勒索钱财.不给钱就删除.但是现在移动设备如此之多,就有一些不法分子想把这个病毒扩散到移动设备了,这几天一个哥们给了一个 ...
- OPEN(SAP) UI5 学习入门系列之二: 最佳实践练习(上)
这篇博文难产了很久,原来是打算一周更新一篇的,上周原计划写MVC,但是写了一半,发现带入了太多的细节,不太符合这个入门系列的主题. 当我们学习一个新的技能的时候,如果一开始就面对大量的细节,很容易陷入 ...
- postfix邮件服务器搭建04-终结篇
本来是计划对postfix做一个全系列的安装文档的,不过在查某个知识点的时候,偶然找到一个已经写好的postfix全系列文章,在全部看完之后惊为天人,我认为:总体上会比我要写的要好,所以我准备借用一下 ...
- 现在很火的数据科学到底是什么?你对做DATA SCIENTIST感兴趣吗?
转自– Warald (Email: iamxiaoning@gmail.com) 博客: http://www.1point3acres.com,微博:http://www.weibo.com/wa ...