Spring的StringUtils⼯具类
本⽂是转载⽂章,感觉⽐较好,如有侵权,请联系本⼈,我将及时删除。
原⽂⽹址:
Utils
我们经常会对字符串进⾏操作,spring已经实现了常⽤的处理功能。我们可以使⽤Utils⼯具类帮我们处理字符串。
⼯具类整理如下:
gth(null)=fal;
gth("")=fal;
gth("")=true;
gth("Hello")=true;
5
t(null)=fal;
t("")=fal;
t("")=fal;
t("12345")=true;
t("12345")=true;
11
12//是否包含空⽩字符
nsWhitespace(null)=fal;
nsWhitespace("")=fal;
nsWhitespace("a")=fal;
nsWhitespace("abc")=fal;
nsWhitespace("abc")=fal;
nsWhitespace("")=true;
nsWhitespace("a")=true;
nsWhitespace("abc")=true;
nsWhitespace("ab")=true
nsWhitespace("ab")
23
itespace(null)=null;
itespace("")="";
itespace("")="";
itespace("/t")="";
itespace("a")="a";
itespace("a")="a";
itespace("a")="a";
itespace("ab")="ab";
32
adingWhitespace(null)=null;
adingWhitespace("")="";
adingWhitespace("")="";
adingWhitespace("/t")="";
adingWhitespace("a")="a";
adingWhitespace("a")="a";
adingWhitespace("a")="a";
adingWhitespace("ab")="ab"
adingWhitespace("abc")="abc"
42
ailingWhitespace(null)=null;
ailingWhitespace("")="";
ailingWhitespace("/t")="";
ailingWhitespace("a")="a";
ailingWhitespace("a")="a";
ailingWhitespace("a")="a";
ailingWhitespace("ab")="ab";
ailingWhitespace("abc")="abc";
51
52
lWhitespace("")="";
lWhitespace("")="";
lWhitespace("/t")="";
lWhitespace("a")="a";
lWhitespace("a")="a";
lWhitespace("a")="a";
lWhitespace("ab")="ab";
lWhitespace("abc"="abc";
61//统计⼀个⼦字符串在字符串出现的次数
ccurrencesOf(null,null)==0;
ccurrencesOf("s",null)==0;
ccurrencesOf(null,"s")==0;
ccurrencesOf("erowoiueoiur","WERWER")==0;
ccurrencesOf("erowoiueoiur","x")=0;
ccurrencesOf("erowoiueoiur","")==0;
ccurrencesOf("erowoiueoiur","")==0;
ccurrencesOf("erowoiueoiur","e")==2;
ccurrencesOf("erowoiueoiur","oi")==2;
ccurrencesOf("erowoiueoiur","oiu")==2;
ccurrencesOf("erowoiueoiur","oiur")==1;
ccurrencesOf("erowoiueoiur","r")==2;
74
75//字符串替换
76StringinString="a6AazAaa77abaa";
77StringoldPattern="aa";
78StringnewPattern="foo";
79//Simplereplace
80Strings=e(inString,oldPattern,newPattern);
("a6AazAfoo77abfoo")=true;
82
83//Nonmatch:nochange
84s=e(inString,"qwoeiruqopwieurpoqwieur",newPattern);
(inString)=true
86s=e(inString,oldPattern,null);
(inString)=true
88
89//Nulloldpattern:shouldignore
90s=e(inString,null,newPattern);
(inString)=true
92
93//删除字符串
94StringinString="Thequickbrownfoxjumpedoverthelazydog";
95StringnoThe=(inString,"the");
("Thequickbrownfoxjumpedoverlazydog")=true;
97Stringnohe=(inString,"he");
("Tquickbrownfoxjumpedovertlazydog")=true;
99Stringnosp=(inString,"");
("Thequickbrownfoxjumpedoverthelazydog")=true;
101StringkillEnd=(inString,"dog");
("Thequickbrownfoxjumpedoverthelazy")=true;
103Stringmismatch=(inString,"dxxcxcxog");
(inString)=true;
105
106//删除任何字符
107//源代码如下
108//charc=(i);
109//如果不存在c值,则返回-1
110//if(f(c)==-1){
111//(c);
112//}
113
114StringinString="AblewasIereIsawElba";
115
116Stringres=Any(inString,"I");
("AblewaresawElba")=true;
118res=Any(inString,"AeEba!");
("lwsIrIswl")=true;
120Stringmismatch=Any(inString,"#@$#$^");
(inString)=true;
122
123//源代码如下return(str!=null?"'"+str+"'":null);
124asrtEquals("'myString'",("myString"));
125asrtEquals("''",(""));
126asrtNull((null));
127//将第⼀个字符改⼤写
lize(Str)
129//将第⼀个个字符改⼩写
talize(str)
131
132//mypath/"->"
133//获取字符串⽂件名和扩展名
ename("myfile").equals("myfile")=true;
ename("mypath/myfile".equals("myfile")=true;
ename("mypath/myfile".equals("myfile")=true;
ename("").equals("")=true;
ename("mypath/").equals("")=true;
139
140//获取字符串扩展名,以.分隔
enameExtension("myfile")=null;
enameExtension("myPath/myfile")=null;
enameExtension("myfile.").equals("")=true;
enameExtension("myPath/myfile.").equals("")=true;
enameExtension("").equals("txt")=true;
enameExtension("mypath/").equals("txt")=true;
147
148//舍去⽂件名扩展名
ilenameExtension(null)=true;
ilenameExtension("").equals("")=true;
ilenameExtension("myfile").equals("myfile")=true;
ilenameExtension("mypath/myfile").equals("mypath/myfile")=true;
ilenameExtension("myfile.").equals("myfile")=true;
ilenameExtension("mypath/myfile.").equals("mypath/myfile")=true;
ilenameExtension("mypath/myfile.").equals("mypath/myfile")=true;
ilenameExtension("").equals("myfile")=true;
ilenameExtension("mypath/").equals("mypath/myfile")=true
本文发布于:2022-12-09 23:09:50,感谢您对本站的认可!
本文链接:http://www.wtabcd.cn/fanwen/fan/88/75517.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |