<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Freddie&#039;s Ria World- org.apache.commons.lang.StringUtil的21个使用技巧（转） &#8211; Blog Title</title>
	<atom:link href="http://javaflex.net/tag/stringutil%e6%95%99%e7%a8%8b/feed/" rel="self" type="application/rss+xml" />
	<link>http://javaflex.net</link>
	<description>Just another flex weblog</description>
	<lastBuildDate>Thu, 19 Aug 2010 08:28:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>zh</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>org.apache.commons.lang.StringUtil的21个使用技巧（转）</title>
		<link>http://javaflex.net/java/stringutil-usage/</link>
		<comments>http://javaflex.net/java/stringutil-usage/#comments</comments>
		<pubDate>Fri, 18 Dec 2009 00:35:43 +0000</pubDate>
		<dc:creator>Freddie</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[StringUtil]]></category>
		<category><![CDATA[StringUtil例子]]></category>
		<category><![CDATA[StringUtil教程]]></category>

		<guid isPermaLink="false">http://javaflex.net/?p=84</guid>
		<description><![CDATA[1.空字符串检查
使用函数: StringUtils.isBlank(testString)
函数介绍: 当testString为空,长度为零或者仅由空白字符(whitespace)组成时,返回True;否则返回False
例程:
    String test = &#8220;&#8221;;
    String test2 = &#8220;\n\n\t&#8221;;
    String test3 = null;
    String test4 = &#8220;Test&#8221;;
    System.out.println( &#8220;test blank? &#8221; + StringUtils.isBlank( test ) );
    System.out.println( &#8220;test2 blank? &#8221; + StringUtils.isBlank( test2 ) );
    System.out.println( &#8220;test3 blank? &#8221; + StringUtils.isBlank( test3 ) );
    System.out.println( &#8220;test4 blank? &#8221; + StringUtils.isBlank( test4 ) );
输出如下:
test [...]]]></description>
			<content:encoded><![CDATA[<p><span style="font-family: Arial;">1.空字符串检查<br />
使用函数: StringUtils.isBlank(testString)<br />
函数介绍: 当testString为空,长度为零或者仅由空白字符(whitespace)组成时,返回True;否则返回False<br />
例程:<br />
    String test = &#8220;&#8221;;<br />
    String test2 = &#8220;\n\n\t&#8221;;<br />
    String test3 = null;<br />
    String test4 = &#8220;Test&#8221;;<br />
    System.out.println( &#8220;test blank? &#8221; + StringUtils.isBlank( test ) );<br />
    System.out.println( &#8220;test2 blank? &#8221; + StringUtils.isBlank( test2 ) );<br />
    System.out.println( &#8220;test3 blank? &#8221; + StringUtils.isBlank( test3 ) );<br />
    System.out.println( &#8220;test4 blank? &#8221; + StringUtils.isBlank( test4 ) );<br />
输出如下:<br />
test blank? true<br />
test2 blank? true<br />
test3 blank? true<br />
test4 blank? False<br />
函数StringUtils.isNotBlank(testString)的功能与StringUtils.isBlank(testString)相反.</span></p>
<p><span style="font-family: Arial;"><br />
2.清除空白字符<br />
使用函数: StringUtils.trimToNull(testString)<br />
函数介绍:清除掉testString首尾的空白字符,如果仅testString全由空白字符<br />
(whitespace)组成则返回null<br />
例程:<br />
    String test1 = &#8220;\t&#8221;;<br />
    String test2 = &#8220;  A  Test  &#8220;;<br />
    String test3 = null;</p>
<p>    System.out.println( &#8220;test1 trimToNull: &#8221; + StringUtils.trimToNull( test1 ) );<br />
    System.out.println( &#8220;test2 trimToNull: &#8221; + StringUtils.trimToNull( test2 ) );<br />
    System.out.println( &#8220;test3 trimToNull: &#8221; + StringUtils.trimToNull( test3 ) );</p>
<p>输出如下:<br />
test1 trimToNull: null<br />
test2 trimToNull: A  Test<br />
test3 trimToNull: null</p>
<p>注意：函数StringUtils.trim(testString)与<br />
StringUtils.trimToNull(testString)功能类似，但testString由空白字符<br />
(whitespace)组成时返回零长度字符串。<br />
3.取得字符串的缩写<br />
使用函数: StringUtils.abbreviate(testString,width)和StringUtils.abbreviate(testString,offset，width)<br />
函数介绍:在给定的width内取得testString的缩写,当testString的长度小于width则返回原字符串.<br />
例程:<br />
    String test = &#8220;This is a test of the abbreviation.&#8221;;<br />
    String test2 = &#8220;Test&#8221;;</p>
<p>    System.out.println( StringUtils.abbreviate( test, 15 ) );<br />
    System.out.println( StringUtils.abbreviate( test, 5,15 ) );<br />
    System.out.println( StringUtils.abbreviate( test2, 10 ) );<br />
输出如下:<br />
This is a te&#8230;<br />
&#8230;is a test&#8230;<br />
Test</p>
<p>4.劈分字符串<br />
使用函数: StringUtils.split(testString,splitChars,arrayLength)<br />
函数介绍:splitChars中可以包含一系列的字符串来劈分testString,并可以设定得<br />
到数组的长度.注意设定长度arrayLength和劈分字符串间有抵触关系,建议一般情况下<br />
不要设定长度.<br />
例程:<br />
    String input = &#8220;A b,c.d|e&#8221;;<br />
    String input2 = &#8220;Pharmacy, basketball funky&#8221;;<br />
   </p>
<p>    String[] array1 = StringUtils.split( input, &#8221; ,.|&#8221;);<br />
    String[] array2 = StringUtils.split( input2, &#8221; ,&#8221;, 2 );<br />
    System.out.println( ArrayUtils.toString( array1 ) );<br />
    System.out.println( ArrayUtils.toString( array2 ) );<br />
输出如下:<br />
{A,b,c,d,e}<br />
{Pharmacy,basketball funky}</p>
<p>5.查找嵌套字符串<br />
使用函数:StringUtils.substringBetween(testString,header,tail)<br />
函数介绍：在testString中取得header和tail之间的字符串。不存在则返回空<br />
例程：<br />
    String htmlContent = &#8220;ABC1234ABC4567&#8243;;<br />
    System.out.println(StringUtils.substringBetween(htmlContent, &#8220;1234&#8243;, &#8220;4567&#8243;));<br />
    System.out.println(StringUtils.substringBetween(htmlContent, &#8220;12345&#8243;, &#8220;4567&#8243;));<br />
输出如下：<br />
    ABC<br />
    null<br />
6.去除尾部换行符<br />
使用函数:StringUtils.chomp(testString)<br />
函数介绍:去除testString尾部的换行符<br />
例程:<br />
    String input = &#8220;Hello\n&#8221;;<br />
    System.out.println( StringUtils.chomp( input ));<br />
    String input2 = &#8220;Another test\r\n&#8221;;<br />
    System.out.println( StringUtils.chomp( input2 ));<br />
输出如下:<br />
    Hello<br />
    Another test<br />
7.重复字符串<br />
使用函数:StringUtils.repeat(repeatString,count)<br />
函数介绍:得到将repeatString重复count次后的字符串<br />
例程:<br />
    System.out.println( StringUtils.repeat( &#8220;*&#8221;, 10));<br />
    System.out.println( StringUtils.repeat( &#8220;China &#8220;, 5));<br />
输出如下:<br />
    **********<br />
    China China China China China</p>
<p>其他函数:StringUtils.center( testString, count,repeatString );<br />
函数介绍:把testString插入将repeatString重复多次后的字符串中间,得到字符串<br />
的总长为count<br />
例程:<br />
    System.out.println( StringUtils.center( &#8220;China&#8221;, 11,&#8221;*&#8221;));<br />
输出如下:<br />
    ***China***<br />
8.颠倒字符串<br />
使用函数:StringUtils.reverse(testString)<br />
函数介绍:得到testString中字符颠倒后的字符串<br />
例程:<br />
    System.out.println( StringUtils.reverse(&#8220;ABCDE&#8221;));<br />
输出如下:<br />
    EDCBA</p>
<p>9.判断字符串内容的类型<br />
函数介绍:<br />
StringUtils.isNumeric( testString ) :如果testString全由数字组成返回True<br />
StringUtils.isAlpha( testString ) :如果testString全由字母组成返回True<br />
StringUtils.isAlphanumeric( testString ) :如果testString全由数字或数字组<br />
成返回True<br />
StringUtils.isAlphaspace( testString )  :如果testString全由字母或空格组<br />
成返回True</p>
<p>例程:<br />
    String state = &#8220;Virginia&#8221;;<br />
    System.out.println( &#8220;Is state number? &#8221; + StringUtils.isNumeric(<br />
state ) );<br />
    System.out.println( &#8220;Is state alpha? &#8221; + StringUtils.isAlpha( state )<br />
);<br />
    System.out.println( &#8220;Is state alphanumeric? &#8221; +StringUtils.isAlphanumeric( state ) );<br />
    System.out.println( &#8220;Is state alphaspace? &#8221; + StringUtils.isAlphaSpace( state ) );<br />
输出如下:<br />
    Is state number? false<br />
    Is state alpha? true<br />
    Is state alphanumeric? true<br />
    Is state alphaspace? true</p>
<p>10.取得某字符串在另一字符串中出现的次数<br />
使用函数:StringUtils.countMatches(testString,seqString)<br />
函数介绍:取得seqString在testString中出现的次数,未发现则返回零<br />
例程:<br />
    System.out.println(StringUtils.countMatches( &#8220;Chinese People&#8221;, &#8220;e&#8221;<br />
));<br />
输出:<br />
    4</p>
<p>11.部分截取字符串<br />
使用函数:<br />
StringUtils.substringBetween(testString,fromString,toString ):取得两字符<br />
之间的字符串<br />
StringUtils.substringAfter( ):取得指定字符串后的字符串<br />
StringUtils.substringBefore( )：取得指定字符串之前的字符串<br />
StringUtils.substringBeforeLast( )：取得最后一个指定字符串之前的字符串<br />
StringUtils.substringAfterLast( )：取得最后一个指定字符串之后的字符串</p>
<p>函数介绍：上面应该都讲明白了吧。<br />
例程：<br />
    String formatted = &#8221; 25 * (30,40) [50,60] | 30&#8243;;<br />
    System.out.print(&#8220;N0: &#8221; + StringUtils.substringBeforeLast( formatted, &#8220;*&#8221; ) );<br />
    System.out.print(&#8220;, N1: &#8221; + StringUtils.substringBetween( formatted, &#8220;(&#8220;, &#8220;,&#8221; ) );<br />
    System.out.print(&#8220;, N2: &#8221; + StringUtils.substringBetween( formatted, &#8220;,&#8221;, &#8220;)&#8221; ) );<br />
    System.out.print(&#8220;, N3: &#8221; + StringUtils.substringBetween( formatted, &#8220;[", "," ) );<br />
    System.out.print(", N4: " + StringUtils.substringBetween( formatted, ",", "]&#8221; ) );<br />
    System.out.print(&#8220;, N5: &#8221; + StringUtils.substringAfterLast( formatted, &#8220;|&#8221; ) );<br />
输出如下：<br />
    N0:  25 , N1: 30, N2: 40, N3: 50, N4: 40) [50,60, N5:  30</p>
<p> </p>
<p> </p>
<p>一、数组转成字符串：<br />
1、 将数组中的字符转换为一个字符串<br />
将数组中的字符转换为一个字符串</p>
<p>@param strToConv 要转换的字符串 ,默认以逗号分隔<br />
@return 返回一个字符串<br />
String[3] s={&#8220;a&#8221;,&#8221;b&#8221;,&#8221;c&#8221;}<br />
StringUtil.convString（s)=&#8221;a,b,c&#8221;<br />
2、 static public String converString(String strToConv)<br />
@param strToConv 要转换的字符串 ,<br />
@param conv 分隔符,默认以逗号分隔<br />
@return 同样返回一个字符串</p>
<p>String[3] s={&#8220;a&#8221;,&#8221;b&#8221;,&#8221;c&#8221;}<br />
StringUtil.convString（s,&#8221;@&#8221;)=&#8221;a@b@c&#8221;<br />
static public String converString(String strToConv, String conv)<br />
二、空值检测：<br />
3、</p>
<p>Checks if a String is empty (&#8220;&#8221;) or null.<br />
判断一个字符串是否为空，空格作非空处理。 StringUtils.isEmpty(null) = true StringUtils.isEmpty(&#8220;&#8221;) = true StringUtils.isEmpty(&#8221; &#8220;) = false StringUtils.isEmpty(&#8220;bob&#8221;) = false StringUtils.isEmpty(&#8221; bob &#8220;) = false</p>
<p>NOTE: This method changed in Lang version 2.0.</p>
<p>It no longer trims the String.<br />
That functionality is available in isBlank().<br />
@param str the String to check, may be null<br />
@return true if the String is empty or null<br />
public static boolean isEmpty(String str)<br />
三、非空处理：<br />
4、<br />
Checks if a String is not empty (&#8220;&#8221;) and not null.<br />
判断一个字符串是否非空，空格作非空处理. StringUtils.isNotEmpty(null) = false StringUtils.isNotEmpty(&#8220;&#8221;) = false StringUtils.isNotEmpty(&#8221; &#8220;) = true StringUtils.isNotEmpty(&#8220;bob&#8221;) = true StringUtils.isNotEmpty(&#8221; bob &#8220;) = true</p>
<p>@param str the String to check, may be null<br />
@return true if the String is not empty and not null<br />
public static boolean isNotEmpty(String str)</p>
<p>5、</p>
<p>Checks if a String is not empty (&#8220;&#8221;), not null and not whitespace only.<br />
判断一个字符串是否非空，空格作空处理. StringUtils.isNotBlank(null) = false StringUtils.isNotBlank(&#8220;&#8221;) = false StringUtils.isNotBlank(&#8221; &#8220;) = false StringUtils.isNotBlank(&#8220;bob&#8221;) = true StringUtils.isNotBlank(&#8221; bob &#8220;) = true</p>
<p>@param str the String to check, may be null<br />
@return true if the String is<br />
not empty and not null and not whitespace<br />
@since 2.0<br />
public static boolean isNotBlank(String str)<br />
四、 空格处理<br />
6、<br />
Removes control characters (char &lt;= 32) from both</p>
<p>ends of this String, handling null by returning<br />
null.<br />
The String is trimmed using {@link String#trim()}.</p>
<p>Trim removes start and end characters &lt;= 32.<br />
To strip whitespace use {@link //strip(String)}.<br />
To trim your choice of characters, use the</p>
<p>{@link //strip(String, String)} methods.<br />
格式化一个字符串中的空格，有非空判断处理； StringUtils.trim(null) = null StringUtils.trim(&#8220;&#8221;) = &#8220;&#8221; StringUtils.trim(&#8221; &#8220;) = &#8220;&#8221; StringUtils.trim(&#8220;abc&#8221;) = &#8220;abc&#8221; StringUtils.trim(&#8221; abc &#8220;) = &#8220;abc&#8221;</p>
<p>@param str the String to be trimmed, may be null<br />
@return the trimmed string, null if null String input<br />
public static String trim(String str)</p>
<p>7、<br />
Removes control characters (char &lt;= 32) from both</p>
<p>ends of this String returning null if the String is<br />
empty (&#8220;&#8221;) after the trim or if it is null.</p>
<p>The String is trimmed using {@link String#trim()}.</p>
<p>Trim removes start and end characters &lt;= 32.<br />
To strip whitespace use {@link /stripToNull(String)}.<br />
格式化一个字符串中的空格，有非空判断处理，如果为空返回null； StringUtils.trimToNull(null) = null StringUtils.trimToNull(&#8220;&#8221;) = null StringUtils.trimToNull(&#8221; &#8220;) = null StringUtils.trimToNull(&#8220;abc&#8221;) = &#8220;abc&#8221; StringUtils.trimToNull(&#8221; abc &#8220;) = &#8220;abc&#8221;</p>
<p>@param str the String to be trimmed, may be null<br />
@return the trimmed String,<br />
null if only chars &lt;= 32, empty or null String input<br />
@since 2.0<br />
public static String trimToNull(String str)</p>
<p>8、<br />
Removes control characters (char &lt;= 32) from both</p>
<p>ends of this String returning an empty String (&#8220;&#8221;) if the String<br />
is empty (&#8220;&#8221;) after the trim or if it is null.</p>
<p>The String is trimmed using {@link String#trim()}.</p>
<p>Trim removes start and end characters &lt;= 32.<br />
To strip whitespace use {@link /stripToEmpty(String)}.<br />
格式化一个字符串中的空格，有非空判断处理，如果为空返回&#8221;"； StringUtils.trimToEmpty(null) = &#8220;&#8221; StringUtils.trimToEmpty(&#8220;&#8221;) = &#8220;&#8221; StringUtils.trimToEmpty(&#8221; &#8220;) = &#8220;&#8221; StringUtils.trimToEmpty(&#8220;abc&#8221;) = &#8220;abc&#8221; StringUtils.trimToEmpty(&#8221; abc &#8220;) = &#8220;abc&#8221;</p>
<p>@param str the String to be trimmed, may be null<br />
@return the trimmed String, or an empty String if null input<br />
@since 2.0<br />
public static String trimToEmpty(String str)<br />
五、 字符串比较:<br />
9、<br />
Compares two Strings, returning true if they are equal.<br />
nulls are handled without exceptions. Two null</p>
<p>references are considered to be equal. The comparison is case sensitive.<br />
判断两个字符串是否相等，有非空处理。 StringUtils.equals(null, null) = true StringUtils.equals(null, &#8220;abc&#8221;) = false StringUtils.equals(&#8220;abc&#8221;, null) = false StringUtils.equals(&#8220;abc&#8221;, &#8220;abc&#8221;) = true StringUtils.equals(&#8220;abc&#8221;, &#8220;ABC&#8221;) = false</p>
<p>@param str1 the first String, may be null<br />
@param str2 the second String, may be null<br />
@return true if the Strings are equal, case sensitive, or<br />
both null<br />
@see java.lang.String#equals(Object)<br />
public static boolean equals(String str1, String str2)<br />
10、</p>
<p>Compares two Strings, returning true if they are equal ignoring</p>
<p>the case.<br />
nulls are handled without exceptions. Two null</p>
<p>references are considered equal. Comparison is case insensitive.<br />
判断两个字符串是否相等，有非空处理。忽略大小写 StringUtils.equalsIgnoreCase(null, null) = true StringUtils.equalsIgnoreCase(null, &#8220;abc&#8221;) = false StringUtils.equalsIgnoreCase(&#8220;abc&#8221;, null) = false StringUtils.equalsIgnoreCase(&#8220;abc&#8221;, &#8220;abc&#8221;) = true StringUtils.equalsIgnoreCase(&#8220;abc&#8221;, &#8220;ABC&#8221;) = true</p>
<p>@param str1 the first String, may be null<br />
@param str2 the second String, may be null<br />
@return true if the Strings are equal, case insensitive, or<br />
both null<br />
@see java.lang.String#equalsIgnoreCase(String)<br />
public static boolean equalsIgnoreCase(String str1, String str2)<br />
六、 IndexOf 处理<br />
11、<br />
Finds the first index within a String, handling null.</p>
<p>This method uses {@link String#indexOf(String)}.<br />
A null String will return -1.<br />
返回要查找的字符串所在位置，有非空处理 StringUtils.indexOf(null, *) = -1 StringUtils.indexOf(*, null) = -1 StringUtils.indexOf(&#8220;&#8221;, &#8220;&#8221;) = 0 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;a&#8221;) = 0 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;b&#8221;) = 2 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;ab&#8221;) = 1 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;&#8221;) = 0</p>
<p>@param str the String to check, may be null<br />
@param searchStr the String to find, may be null<br />
@return the first index of the search String,<br />
-1 if no match or null string input<br />
@since 2.0<br />
public static int indexOf(String str, String searchStr)</p>
<p>12、</p>
<p>Finds the first index within a String, handling null.</p>
<p>This method uses {@link String#indexOf(String, int)}.<br />
A null String will return -1.</p>
<p>A negative start position is treated as zero.<br />
An empty (&#8220;&#8221;) search String always matches.<br />
A start position greater than the string length only matches<br />
an empty search String.<br />
返回要由指定位置开始查找的字符串所在位置，有非空处理 StringUtils.indexOf(null, *, *) = -1 StringUtils.indexOf(*, null, *) = -1 StringUtils.indexOf(&#8220;&#8221;, &#8220;&#8221;, 0) = 0 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;a&#8221;, 0) = 0 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;b&#8221;, 0) = 2 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;ab&#8221;, 0) = 1 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;b&#8221;, 3) = 5 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;b&#8221;, 9) = -1 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;b&#8221;, -1) = 2 StringUtils.indexOf(&#8220;aabaabaa&#8221;, &#8220;&#8221;, 2) = 2 StringUtils.indexOf(&#8220;abc&#8221;, &#8220;&#8221;, 9) = 3</p>
<p>@param str the String to check, may be null<br />
@param searchStr the String to find, may be null<br />
@param startPos the start position, negative treated as zero<br />
@return the first index of the search String,<br />
-1 if no match or null string input<br />
@since 2.0<br />
public static int indexOf(String str, String searchStr, int startPos)<br />
七、 子字符串处理：<br />
13、<br />
Gets a substring from the specified String avoiding exceptions.<br />
A negative start position can be used to start n</p>
<p>characters from the end of the String.<br />
A null String will return null.</p>
<p>An empty (&#8220;&#8221;) String will return &#8220;&#8221;.<br />
返回指定位置开始的字符串中的所有字符 StringUtils.substring(null, *) = null StringUtils.substring(&#8220;&#8221;, *) = &#8220;&#8221; StringUtils.substring(&#8220;abc&#8221;, 0) = &#8220;abc&#8221; StringUtils.substring(&#8220;abc&#8221;, 2) = &#8220;c&#8221; StringUtils.substring(&#8220;abc&#8221;, 4) = &#8220;&#8221; StringUtils.substring(&#8220;abc&#8221;, -2) = &#8220;bc&#8221; StringUtils.substring(&#8220;abc&#8221;, -4) = &#8220;abc&#8221;</p>
<p>@param str the String to get the substring from, may be null<br />
@param start the position to start from, negative means<br />
count back from the end of the String by this many characters<br />
@return substring from start position, null if null String input<br />
public static String substring(String str, int start)</p>
<p>14、</p>
<p>Gets a substring from the specified String avoiding exceptions.<br />
A negative start position can be used to start/end n</p>
<p>characters from the end of the String.<br />
The returned substring starts with the character in the start</p>
<p>position and ends before the end position. All postion counting is<br />
zero-based &#8212; i.e., to start at the beginning of the string use<br />
start = 0. Negative start and end positions can be used to<br />
specify offsets relative to the end of the String.<br />
If start is not strictly to the left of end, &#8220;&#8221;</p>
<p>is returned.<br />
返回由开始位置到结束位置之间的子字符串 StringUtils.substring(null, *, *) = null StringUtils.substring(&#8220;&#8221;, * , *) = &#8220;&#8221;; StringUtils.substring(&#8220;abc&#8221;, 0, 2) = &#8220;ab&#8221; StringUtils.substring(&#8220;abc&#8221;, 2, 0) = &#8220;&#8221; StringUtils.substring(&#8220;abc&#8221;, 2, 4) = &#8220;c&#8221; StringUtils.substring(&#8220;abc&#8221;, 4, 6) = &#8220;&#8221; StringUtils.substring(&#8220;abc&#8221;, 2, 2) = &#8220;&#8221; StringUtils.substring(&#8220;abc&#8221;, -2, -1) = &#8220;b&#8221; StringUtils.substring(&#8220;abc&#8221;, -4, 2) = &#8220;ab&#8221;</p>
<p>@param str the String to get the substring from, may be null<br />
@param start the position to start from, negative means<br />
count back from the end of the String by this many characters<br />
@param end the position to end at (exclusive), negative means<br />
count back from the end of the String by this many characters<br />
@return substring from start position to end positon,<br />
null if null String input<br />
public static String substring(String str, int start, int end)<br />
15、 SubStringAfter/SubStringBefore（前后子字符串处理：<br />
Gets the substring before the first occurance of a separator.</p>
<p>The separator is not returned.<br />
A null string input will return null.</p>
<p>An empty (&#8220;&#8221;) string input will return the empty string.<br />
A null separator will return the input string.<br />
返回指定字符串之前的所有字符 StringUtils.substringBefore(null, *) = null StringUtils.substringBefore(&#8220;&#8221;, *) = &#8220;&#8221; StringUtils.substringBefore(&#8220;abc&#8221;, &#8220;a&#8221;) = &#8220;&#8221; StringUtils.substringBefore(&#8220;abcba&#8221;, &#8220;b&#8221;) = &#8220;a&#8221; StringUtils.substringBefore(&#8220;abc&#8221;, &#8220;c&#8221;) = &#8220;ab&#8221; StringUtils.substringBefore(&#8220;abc&#8221;, &#8220;d&#8221;) = &#8220;abc&#8221; StringUtils.substringBefore(&#8220;abc&#8221;, &#8220;&#8221;) = &#8220;&#8221; StringUtils.substringBefore(&#8220;abc&#8221;, null) = &#8220;abc&#8221;</p>
<p>@param str the String to get a substring from, may be null<br />
@param separator the String to search for, may be null<br />
@return the substring before the first occurance of the separator,<br />
null if null String input<br />
@since 2.0<br />
public static String substringBefore(String str, String separator)</p>
<p>16、</p>
<p>Gets the substring after the first occurance of a separator.</p>
<p>The separator is not returned.<br />
A null string input will return null.</p>
<p>An empty (&#8220;&#8221;) string input will return the empty string.<br />
A null separator will return the empty string if the<br />
input string is not null.<br />
返回指定字符串之后的所有字符 StringUtils.substringAfter(null, *) = null StringUtils.substringAfter(&#8220;&#8221;, *) = &#8220;&#8221; StringUtils.substringAfter(*, null) = &#8220;&#8221; StringUtils.substringAfter(&#8220;abc&#8221;, &#8220;a&#8221;) = &#8220;bc&#8221; StringUtils.substringAfter(&#8220;abcba&#8221;, &#8220;b&#8221;) = &#8220;cba&#8221; StringUtils.substringAfter(&#8220;abc&#8221;, &#8220;c&#8221;) = &#8220;&#8221; StringUtils.substringAfter(&#8220;abc&#8221;, &#8220;d&#8221;) = &#8220;&#8221; StringUtils.substringAfter(&#8220;abc&#8221;, &#8220;&#8221;) = &#8220;abc&#8221;</p>
<p>@param str the String to get a substring from, may be null<br />
@param separator the String to search for, may be null<br />
@return the substring after the first occurance of the separator,<br />
null if null String input<br />
@since 2.0<br />
public static String substringAfter(String str, String separator)</p>
<p>17、</p>
<p>Gets the substring before the last occurance of a separator.</p>
<p>The separator is not returned.<br />
A null string input will return null.</p>
<p>An empty (&#8220;&#8221;) string input will return the empty string.<br />
An empty or null separator will return the input string.<br />
返回最后一个指定字符串之前的所有字符 StringUtils.substringBeforeLast(null, *) = null StringUtils.substringBeforeLast(&#8220;&#8221;, *) = &#8220;&#8221; StringUtils.substringBeforeLast(&#8220;abcba&#8221;, &#8220;b&#8221;) = &#8220;abc&#8221; StringUtils.substringBeforeLast(&#8220;abc&#8221;, &#8220;c&#8221;) = &#8220;ab&#8221; StringUtils.substringBeforeLast(&#8220;a&#8221;, &#8220;a&#8221;) = &#8220;&#8221; StringUtils.substringBeforeLast(&#8220;a&#8221;, &#8220;z&#8221;) = &#8220;a&#8221; StringUtils.substringBeforeLast(&#8220;a&#8221;, null) = &#8220;a&#8221; StringUtils.substringBeforeLast(&#8220;a&#8221;, &#8220;&#8221;) = &#8220;a&#8221;</p>
<p>@param str the String to get a substring from, may be null<br />
@param separator the String to search for, may be null<br />
@return the substring before the last occurance of the separator,<br />
null if null String input<br />
@since 2.0<br />
public static String substringBeforeLast(String str, String separator)</p>
<p>18、</p>
<p>Gets the substring after the last occurance of a separator.</p>
<p>The separator is not returned.<br />
A null string input will return null.</p>
<p>An empty (&#8220;&#8221;) string input will return the empty string.<br />
An empty or null separator will return the empty string if<br />
the input string is not null.<br />
返回最后一个指定字符串之后的所有字符 StringUtils.substringAfterLast(null, *) = null StringUtils.substringAfterLast(&#8220;&#8221;, *) = &#8220;&#8221; StringUtils.substringAfterLast(*, &#8220;&#8221;) = &#8220;&#8221; StringUtils.substringAfterLast(*, null) = &#8220;&#8221; StringUtils.substringAfterLast(&#8220;abc&#8221;, &#8220;a&#8221;) = &#8220;bc&#8221; StringUtils.substringAfterLast(&#8220;abcba&#8221;, &#8220;b&#8221;) = &#8220;a&#8221; StringUtils.substringAfterLast(&#8220;abc&#8221;, &#8220;c&#8221;) = &#8220;&#8221; StringUtils.substringAfterLast(&#8220;a&#8221;, &#8220;a&#8221;) = &#8220;&#8221; StringUtils.substringAfterLast(&#8220;a&#8221;, &#8220;z&#8221;) = &#8220;&#8221;</p>
<p>@param str the String to get a substring from, may be null<br />
@param separator the String to search for, may be null<br />
@return the substring after the last occurance of the separator,<br />
null if null String input<br />
@since 2.0<br />
public static String substringAfterLast(String str, String separator)<br />
八、 Replacing（字符串替换）<br />
19、<br />
Replaces all occurances of a String within another String.<br />
A null reference passed to this method is a no-op.<br />
以指定字符串替换原来字符串的的指定字符串 StringUtils.replace(null, *, *) = null StringUtils.replace(&#8220;&#8221;, *, *) = &#8220;&#8221; StringUtils.replace(&#8220;aba&#8221;, null, null) = &#8220;aba&#8221; StringUtils.replace(&#8220;aba&#8221;, null, null) = &#8220;aba&#8221; StringUtils.replace(&#8220;aba&#8221;, &#8220;a&#8221;, null) = &#8220;aba&#8221; StringUtils.replace(&#8220;aba&#8221;, &#8220;a&#8221;, &#8220;&#8221;) = &#8220;aba&#8221; StringUtils.replace(&#8220;aba&#8221;, &#8220;a&#8221;, &#8220;z&#8221;) = &#8220;zbz&#8221;</p>
<p>@param text text to search and replace in, may be null<br />
@param repl the String to search for, may be null<br />
@param with the String to replace with, may be null<br />
@return the text with any replacements processed,<br />
null if null String input<br />
@see #replace(String text, String repl, String with, int max)<br />
public static String replace(String text, String repl, String with)</p>
<p>20、</p>
<p>Replaces a String with another String inside a larger String,</p>
<p>for the first max values of the search String.<br />
A null reference passed to this method is a no-op.<br />
以指定字符串最大替换原来字符串的的指定字符串 StringUtils.replace(null, *, *, *) = null StringUtils.replace(&#8220;&#8221;, *, *, *) = &#8220;&#8221; StringUtils.replace(&#8220;abaa&#8221;, null, null, 1) = &#8220;abaa&#8221; StringUtils.replace(&#8220;abaa&#8221;, null, null, 1) = &#8220;abaa&#8221; StringUtils.replace(&#8220;abaa&#8221;, &#8220;a&#8221;, null, 1) = &#8220;abaa&#8221; StringUtils.replace(&#8220;abaa&#8221;, &#8220;a&#8221;, &#8220;&#8221;, 1) = &#8220;abaa&#8221; StringUtils.replace(&#8220;abaa&#8221;, &#8220;a&#8221;, &#8220;z&#8221;, 0) = &#8220;abaa&#8221; StringUtils.replace(&#8220;abaa&#8221;, &#8220;a&#8221;, &#8220;z&#8221;, 1) = &#8220;zbaa&#8221; StringUtils.replace(&#8220;abaa&#8221;, &#8220;a&#8221;, &#8220;z&#8221;, 2) = &#8220;zbza&#8221; StringUtils.replace(&#8220;abaa&#8221;, &#8220;a&#8221;, &#8220;z&#8221;, -1) = &#8220;zbzz&#8221;</p>
<p>@param text text to search and replace in, may be null<br />
@param repl the String to search for, may be null<br />
@param with the String to replace with, may be null<br />
@param max maximum number of values to replace, or -1 if no maximum<br />
@return the text with any replacements processed,<br />
null if null String input<br />
public static String replace(String text, String repl, String with, int max)<br />
九、 Case conversion（大小写转换）<br />
21、</p>
<p>Converts a String to upper case as per {@link String#toUpperCase()}.<br />
A null input String returns null.<br />
将一个字符串变为大写 StringUtils.upperCase(null) = null StringUtils.upperCase(&#8220;&#8221;) = &#8220;&#8221; StringUtils.upperCase(&#8220;aBc&#8221;) = &#8220;ABC&#8221;</p>
<p>@param str the String to upper case, may be null<br />
@return the upper cased String, null if null String input<br />
public static String upperCase(String str) 22、</p>
<p>Converts a String to lower case as per {@link String#toLowerCase()}.<br />
A null input String returns null.<br />
将一个字符串转换为小写 StringUtils.lowerCase(null) = null StringUtils.lowerCase(&#8220;&#8221;) = &#8220;&#8221; StringUtils.lowerCase(&#8220;aBc&#8221;) = &#8220;abc&#8221;</p>
<p>@param str the String to lower case, may be null<br />
@return the lower cased String, null if null String input<br />
public static String lowerCase(String str) 23、</p>
<p>Capitalizes a String changing the first letter to title case as</p>
<p>per {@link Character#toTitleCase(char)}. No other letters are changed.<br />
For a word based alorithm, see {@link /WordUtils#capitalize(String)}.</p>
<p>A null input String returns null.<br />
StringUtils.capitalize(null) = null StringUtils.capitalize(&#8220;&#8221;) = &#8220;&#8221; StringUtils.capitalize(&#8220;cat&#8221;) = &#8220;Cat&#8221; StringUtils.capitalize(&#8220;cAt&#8221;) = &#8220;CAt&#8221;</p>
<p>@param str the String to capitalize, may be null<br />
@return the capitalized String, null if null String input<br />
@see /WordUtils#capitalize(String)<br />
@see /uncapitalize(String)<br />
@since 2.0<br />
将字符串中的首字母大写<br />
public static String capitalize(String str)</p>
<p></span></p>
<div id="crp_related"><h3>您可能也会关注:</h3><ul><li><a href="http://javaflex.net/flex/flexblazedsspring/" rel="bookmark" class="crp_title">flex+BlazeDS与spring集成</a></li><li><a href="http://javaflex.net/flex/mxml-create-array/" rel="bookmark" class="crp_title">1.8在MXML中创建数组或对象</a></li><li><a href="http://javaflex.net/flex/mxml-create-array-2/" rel="bookmark" class="crp_title">1.8在MXML中创建数组或对象</a></li><li><a href="http://javaflex.net/java/spring-hql-gethibernatetemplate/" rel="bookmark" class="crp_title">Spring中常用的hql查询方法(getHibernateTemplate())(转)</a></li><li><a href="http://javaflex.net/java/tomcat/" rel="bookmark" class="crp_title">使用嵌入式 Tomcat 简化程序调试</a></li></ul></div>

<!-- Begin SexyBookmarks Menu Code -->
<div class="sexy-bookmarks sexy-bookmarks-expand">
<ul class="socials">
		<li class="sexy-delicious">
			<a href="http://delicious.com/post?url=http://javaflex.net/java/stringutil-usage/&amp;title=org.apache.commons.lang.StringUtil%E7%9A%8421%E4%B8%AA%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%EF%BC%88%E8%BD%AC%EF%BC%89" rel="nofollow" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="sexy-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://javaflex.net/java/stringutil-usage/&amp;t=org.apache.commons.lang.StringUtil%E7%9A%8421%E4%B8%AA%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%EF%BC%88%E8%BD%AC%EF%BC%89" rel="nofollow" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="sexy-twitter">
			<a href="http://twitter.com/home?status=org.apache.commons.lang.StringUtil%E7%9A%8421%E4%B8%AA%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%EF%BC%88%E8%BD%AC%EF%BC%89+-+http://b2l.me/q5yhv+&amp;source=shareaholic" rel="nofollow" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="sexy-comfeed">
			<a href="http://javaflex.net/java/stringutil-usage/feed" rel="nofollow" title="Subscribe to the comments for this post?">Subscribe to the comments for this post?</a>
		</li>
		<li class="sexy-googlebookmarks">
			<a href="http://www.google.com/bookmarks/mark?op=add&amp;bkmk=http://javaflex.net/java/stringutil-usage/&amp;title=org.apache.commons.lang.StringUtil%E7%9A%8421%E4%B8%AA%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%EF%BC%88%E8%BD%AC%EF%BC%89" rel="nofollow" title="Add this to Google Bookmarks">Add this to Google Bookmarks</a>
		</li>
		<li class="sexy-googlereader">
			<a href="http://www.google.com/reader/link?url=http://javaflex.net/java/stringutil-usage/&amp;title=org.apache.commons.lang.StringUtil%E7%9A%8421%E4%B8%AA%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%EF%BC%88%E8%BD%AC%EF%BC%89&amp;srcUrl=http://javaflex.net/java/stringutil-usage/&amp;srcTitle=org.apache.commons.lang.StringUtil%E7%9A%8421%E4%B8%AA%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%EF%BC%88%E8%BD%AC%EF%BC%89&amp;snippet=POST_SUMMARY" rel="nofollow" title="Add this to Google Reader">Add this to Google Reader</a>
		</li>
		<li class="sexy-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://javaflex.net/java/stringutil-usage/&amp;imageurl=" rel="nofollow" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="sexy-blogger">
			<a href="http://www.blogger.com/blog_this.pyra?t&amp;u=http://javaflex.net/java/stringutil-usage/&amp;n=org.apache.commons.lang.StringUtil%E7%9A%8421%E4%B8%AA%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%EF%BC%88%E8%BD%AC%EF%BC%89&amp;pli=1" rel="nofollow" title="Blog this on Blogger">Blog this on Blogger</a>
		</li>
		<li class="sexy-dzone">
			<a href="http://www.dzone.com/links/add.html?url=http://javaflex.net/java/stringutil-usage/&amp;title=org.apache.commons.lang.StringUtil%E7%9A%8421%E4%B8%AA%E4%BD%BF%E7%94%A8%E6%8A%80%E5%B7%A7%EF%BC%88%E8%BD%AC%EF%BC%89&amp;description=POST_SUMMARY" rel="nofollow" title="Add this to DZone">Add this to DZone</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>
<!-- End SexyBookmarks Menu Code -->

]]></content:encoded>
			<wfw:commentRss>http://javaflex.net/java/stringutil-usage/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
