|
publicstaticvoidTestStr(){
002 | //null 和 ""操作~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
004 | //System.out.println(StringUtils.isEmpty(null)); |
005 | //System.out.println(StringUtils.isNotEmpty(null)); |
006 | //判断是否null 或者 "" 去空格~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
007 | //System.out.println(StringUtils.isBlank(" ")); |
008 | //System.out.println(StringUtils.isNotBlank(null)); |
009 | //去空格.Null返回null~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
010 | //System.out.println(StringUtils.trim(null)); |
011 | //去空格,将Null和"" 转换为Null |
012 | //System.out.println(StringUtils.trimToNull("")); |
013 | //去空格,将NULL 和 "" 转换为"" |
014 | //System.out.println(StringUtils.trimToEmpty(null)); |
016 | //System.out.println(StringUtils.strip("大家好 啊 \t")); |
018 | //System.out.println(StringUtils.stripToNull(" \t")); |
020 | //System.out.println(StringUtils.stripToEmpty(null)); |
022 | //System.out.println(StringUtils.defaultString(null)); |
023 | //仅当字符串为Null时 转换为指定的字符串(二参数) |
024 | //System.out.println(StringUtils.defaultString("", "df")); |
025 | //当字符串为null或者""时,转换为指定的字符串(二参数) |
026 | //System.out.println(StringUtils.defaultIfEmpty(null, "sos")); |
027 | //去空格.去字符~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
028 | //如果第二个参数为null去空格(否则去掉字符串2边一样的字符,到不一样为止) |
029 | //System.out.println(StringUtils.strip("fsfsdf", "f")); |
030 | //如果第二个参数为null只去前面空格(否则去掉字符串前面一样的字符,到不一样为止) |
031 | //System.out.println(StringUtils.stripStart("ddsuuu ", "d")); |
032 | //如果第二个参数为null只去后面空格,(否则去掉字符串后面一样的字符,到不一样为止) |
033 | //System.out.println(StringUtils.stripEnd("dabads", "das")); |
035 | //ArrayToList(StringUtils.stripAll(new String[]{" 中华 ", "民 国 ", "共和 "})); |
036 | //如果第二个参数为null.对数组每个字符串进行去空格。(否则去掉数组每个元素开始和结尾一样的字符) |
037 | //ArrayToList(StringUtils.stripAll(new String[]{" 中华 ", "民 国", "国共和国"}, "国")); |
038 | //查找,判断~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
039 | //判断2个字符串是否相等相等,Null也相等 |
040 | //System.out.println(StringUtils.equals(null, null)); |
042 | //System.out.println(StringUtils.equalsIgnoreCase("abc", "ABc")); |
043 | //查找,不知道怎么弄这么多查找,很多不知道区别在哪?费劲~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
044 | //普通查找字符,如果一参数为null或者""返回-1 |
045 | //System.out.println(StringUtils.indexOf(null, "a")); |
046 | //从指定位置(三参数)开始查找,本例从第2个字符开始查找k字符 |
047 | //System.out.println(StringUtils.indexOf("akfekcd中华", "k", 2)); |
049 | //System.out.println(StringUtils.ordinalIndexOf("akfekcd中华", "k", 2)); |
051 | //System.out.println(StringUtils.indexOfIgnoreCase("adfs", "D")); |
052 | //从指定位置(三参数)开始查找,不区分大小写 |
053 | //System.out.println(StringUtils.indexOfIgnoreCase("adfs", "a", 3)); |
055 | //System.out.println(StringUtils.lastIndexOf("adfas", "a")); |
057 | //System.out.println(StringUtils.lastIndexOf("d饿abasdafs我", "a", 3)); |
059 | //System.out.println(StringUtils.lastOrdinalIndexOf("yksdfdht", "f", 2)); |
061 | //System.out.println(StringUtils.lastIndexOfIgnoreCase("sdffet", "E")); |
063 | //System.out.println(StringUtils.lastIndexOfIgnoreCase("efefrfs看", "F" , 2)); |
064 | //检查是否查到,返回boolean,null返回假 |
065 | //System.out.println(StringUtils.contains("sdf", "dg")); |
066 | //检查是否查到,返回boolean,null返回假,不区分大小写 |
067 | //System.out.println(StringUtils.containsIgnoreCase("sdf", "D")); |
068 | //检查是否有含有空格,返回boolean |
069 | //System.out.println(StringUtils.containsWhitespace(" d")); |
070 | //查询字符串跟数组任一元素相同的第一次相同的位置 |
071 | //System.out.println(StringUtils.indexOfAny("absfekf", new String[]{"f", "b"})); |
072 | //查询字符串中指定字符串(参数二)出现的次数 |
073 | //System.out.println(StringUtils.indexOfAny("afefes", "e")); |
074 | //查找字符串中是否有字符数组中相同的字符,返回boolean |
075 | //System.out.println(StringUtils.containsAny("asfsd", new char[]{'k', 'e', 's'})); |
076 | //未理解与lastIndexOf不同之处。是否查到,返回boolean |
077 | //System.out.println(StringUtils.containsAny("啡f咖啡", "咖")); |
079 | //System.out.println(StringUtils.indexOfAnyBut("seefaff", "af")); |
080 | //判断字符串中所有字符,都是出自参数二中。 |
081 | //System.out.println(StringUtils.containsOnly("中华华", "华")); |
082 | //判断字符串中所有字符,都是出自参数二的数组中。 |
083 | //System.out.println(StringUtils.containsOnly("中华中", new char[]{'中', '华'})); |
084 | //判断字符串中所有字符,都不在参数二中。 |
085 | //System.out.println(StringUtils.containsNone("中华华", "国")); |
086 | //判断字符串中所有字符,都不在参数二的数组中。 |
087 | //System.out.println(StringUtils.containsNone("中华中", new char[]{'中', '达人'})); |
088 | //从后往前查找字符串中与字符数组中相同的元素第一次出现的位置。本例为4 |
089 | //System.out.println(StringUtils.lastIndexOfAny("中国人民共和国", new String[]{"国人", "共和"})); |
090 | //未发现与indexOfAny不同之处 查询字符串中指定字符串(参数二)出现的次数 |
091 | //System.out.println(StringUtils.countMatches("中国人民共和中国", "中国")); |
092 | //检查是否CharSequence的只包含Unicode的字母。空将返回false。一个空的CharSequence(长()= 0)将返回true |
093 | //System.out.println(StringUtils.isAlpha("这是干什么的2")); |
094 | //检查是否只包含Unicode的CharSequence的字母和空格('')。空将返回一个空的CharSequence假(长()= 0)将返回true。 |
095 | //System.out.println(StringUtils.isAlphaSpace("NBA直播 ")); |
096 | //检查是否只包含Unicode的CharSequence的字母或数字。空将返回false。一个空的CharSequence(长()= 0)将返回true。 |
097 | //System.out.println(StringUtils.isAlphanumeric("NBA直播")); |
098 | //如果检查的Unicode CharSequence的只包含字母,数字或空格('')。空将返回false。一个空的CharSequence(长()= 0)将返回true。 |
099 | //System.out.println(StringUtils.isAlphanumericSpace("NBA直播")); |
100 | //检查是否只包含ASCII可CharSequence的字符。空将返回false。一个空的CharSequence(长()= 0)将返回true。 |
101 | //System.out.println(StringUtils.isAsciiPrintable("NBA直播")); |
103 | //System.out.println(StringUtils.isNumeric("NBA直播")); |
105 | //System.out.println(StringUtils.isNumericSpace("33 545")); |
107 | //System.out.println(StringUtils.isWhitespace(" ")); |
109 | //System.out.println(StringUtils.isAllLowerCase("kjk33")); |
111 | //System.out.println(StringUtils.isAllUpperCase("KJKJ")); |
112 | //交集操作~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
113 | //去掉参数2字符串中在参数一中开头部分共有的部分,结果为:人民共和加油 |
114 | //System.out.println(StringUtils.difference("中国加油", "中国人民共和加油")); |
116 | //System.out.println(StringUtils.indexOfDifference("ww.taobao", "www.taobao.com")); |
117 | //统计数组中各个元素的字符串开始都一样的字符个数 |
118 | //System.out.println(StringUtils.indexOfDifference(new String[] {"中国加油", "中国共和", "中国人民"})); |
120 | //System.out.println(StringUtils.getCommonPrefix(new String[] {"中国加油", "中国共和", "中国人民"})); |
121 | //统计参数一中每个字符与参数二中每个字符不同部分的字符个数 |
122 | //System.out.println(StringUtils.getLevenshteinDistance("中国共和发国人民", "共和国")); |
124 | //System.out.println(StringUtils.startsWith("中国共和国人民", "中国")); |
125 | //判断开始部分是否与二参数相同。不区分大小写 |
126 | //System.out.println(StringUtils.startsWithIgnoreCase("中国共和国人民", "中国")); |
127 | //判断字符串开始部分是否与数组中的某一元素相同 |
128 | //System.out.println(StringUtils.startsWithAny("abef", new String[]{"ge", "af", "ab"})); |
130 | //System.out.println(StringUtils.endsWith("abcdef", "def")); |
132 | //System.out.println(StringUtils.endsWithIgnoreCase("abcdef", "Def")); |
133 | //字符串截取~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
134 | //截取指定位置的字符,null返回null.""返回"" |
135 | //System.out.println(StringUtils.substring("国民党", 2)); |
137 | //System.out.println(StringUtils.substring("中国人民共和国", 2, 4)); |
139 | //System.out.println(StringUtils.left("说点什么好呢", 3)); |
141 | //System.out.println(StringUtils.right("说点什么好呢", 3)); |
142 | //从第几个开始截取,三参数表示截取的长度 |
143 | //System.out.println(StringUtils.mid("说点什么好呢", 3, 2)); |
145 | //System.out.println(StringUtils.substringBefore("说点什么好呢", "好")); |
146 | //从左往右查到相等的字符开始,保留后边的,不包含等于的字符。本例:什么好呢 |
147 | //System.out.println(StringUtils.substringAfter("说点什么好呢", "点")); |
148 | //这个也是截取到相等的字符,但是是从右往左.本例结果:说点什么好 |
149 | //System.out.println(StringUtils.substringBeforeLast("说点什么好点呢", "点")); |
150 | //这个截取同上是从右往左。但是保留右边的字符 |
151 | //System.out.println(StringUtils.substringAfterLast("说点什么好点呢?", "点")); |
152 | //截取查找到第一次的位置,和第二次的位置中间的字符。如果没找到第二个返回null。本例结果:2010世界杯在 |
153 | //System.out.println(StringUtils.substringBetween("南非2010世界杯在南非,在南非", "南非")); |
154 | //返回参数二和参数三中间的字符串,返回数组形式 |
155 | //ArrayToList(StringUtils.substringsBetween("[a][c]", "[", "]")); |
156 | //分割~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
158 | //ArrayToList(StringUtils.split("中华 人民 共和")); |
160 | //ArrayToList(StringUtils.split("中华 ,人民,共和", ",")); |
161 | //以指定字符分割成数组,第三个参数表示分隔成数组的长度,如果为0全体分割 |
162 | //ArrayToList(StringUtils.split("中华 :人民:共和", ":", 2)); |
164 | //ArrayToList(StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-")); |
165 | //未发现不同的地方,以指定字符分割成数组,第三个参数表示分隔成数组的长度 |
166 | //ArrayToList(StringUtils.splitByWholeSeparator("ab-!-cd-!-ef", "-!-", 2)); |
167 | //分割,但" "不会被忽略算一个元素,二参数为null默认为空格分隔 |
168 | //ArrayToList(StringUtils.splitByWholeSeparatorPreserveAllTokens(" ab de fg ", null)); |
169 | //同上,分割," "不会被忽略算一个元素。第三个参数代表分割的数组长度。 |
170 | //ArrayToList(StringUtils.splitByWholeSeparatorPreserveAllTokens("ab de fg", null, 3)); |
172 | //ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ")); |
174 | //ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ", null)); |
175 | //未发现不同地方,以指定字符分割成数组,第三个参数表示分隔成数组的长度 |
176 | //ArrayToList(StringUtils.splitPreserveAllTokens(" ab de fg ", null, 2)); |
178 | //ArrayToList(StringUtils.splitByCharacterType("AEkjKr i39:。中文")); |
180 | //ArrayToList(StringUtils.splitByCharacterTypeCamelCase("ASFSRules234")); |
181 | //拼接~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
183 | //System.out.println(StringUtils.concat(getArrayData())); |
184 | //拼接时用参数一得字符相连接.注意null也用连接符连接了 |
185 | //System.out.println(StringUtils.concatWith(",", getArrayData())); |
187 | //System.out.println(StringUtils.join(getArrayData())); |
189 | //System.out.println(StringUtils.join(getArrayData(), ":")); |
190 | //拼接指定数组下标的开始(三参数)和结束(四参数,不包含)的中间这些元素,用连接符连接 |
191 | //System.out.println(StringUtils.join(getArrayData(), ":", 1, 3)); |
193 | //System.out.println(StringUtils.join(getListData(), ":")); |
194 | //移除,删除~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
196 | //System.out.println(StringUtils.deleteWhitespace(" s 中 你 4j")); |
198 | //System.out.println(StringUtils.removeStart("www.baidu.com", "www.")); |
199 | //移除开始部分的相同的字符,不区分大小写 |
200 | //System.out.println(StringUtils.removeStartIgnoreCase("www.baidu.com", "WWW")); |
202 | //System.out.println(StringUtils.removeEnd("www.baidu.com", ".com")); |
204 | //System.out.println(StringUtils.removeEndIgnoreCase("www.baidu.com", ".COM")); |
206 | //System.out.println(StringUtils.remove("www.baidu.com/baidu", "bai")); |
207 | //移除结尾字符为"\n", "\r", 或者 "\r\n". |
208 | //System.out.println(StringUtils.chomp("abcrabc\r")); |
210 | //System.out.println(StringUtils.chomp("baidu.com", "com")); |
211 | //去掉末尾最后一个字符.如果是"\n", "\r", 或者 "\r\n"也去除 |
212 | //System.out.println(StringUtils.chop("wwe.baidu")); |
213 | //替换~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
215 | //System.out.println(StringUtils.replaceOnce("www.baidu.com/baidu", "baidu", "hao123")); |
217 | //System.out.println(StringUtils.replace("www.baidu.com/baidu", "baidu", "hao123")); |
219 | //System.out.println(StringUtils.replace("www.baidu.com/baidu", "baidu", "hao123", 1)); |
[table][tr][td]220[/td][td] java comme |
|