Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
Y
yzg-util
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
YZG
yzg-util
Commits
5a2d7d16
Commit
5a2d7d16
authored
Nov 20, 2020
by
yanzg
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
修改实体位置
parent
da48caf3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
90 additions
and
61 deletions
+90
-61
StringHelper.java
...c/main/java/com/yanzuoguang/util/helper/StringHelper.java
+81
-61
TestStringHelper.java
yzg-util-base/src/test/java/helper/TestStringHelper.java
+9
-0
No files found.
yzg-util-base/src/main/java/com/yanzuoguang/util/helper/StringHelper.java
View file @
5a2d7d16
...
@@ -710,48 +710,6 @@ public class StringHelper {
...
@@ -710,48 +710,6 @@ public class StringHelper {
return
sb
.
toString
();
return
sb
.
toString
();
}
}
/**
* 去掉两边的空格
*
* @param from 需要去掉空格的字符串
* @return 去掉字符串的值
*/
public
static
String
trim
(
String
from
)
{
if
(
from
==
null
)
{
return
EMPTY
;
}
return
from
.
trim
();
}
/**
* 去掉左边的字符串
*
* @param from
* @param left
* @return
*/
public
static
String
trimLeft
(
String
from
,
String
...
left
)
{
int
pos
=
0
;
boolean
isHandle
;
do
{
isHandle
=
false
;
for
(
String
item
:
left
)
{
int
size
=
item
.
length
();
if
(
from
.
indexOf
(
item
,
pos
)
==
pos
)
{
isHandle
=
true
;
pos
+=
size
;
continue
;
}
}
}
while
(
isHandle
);
if
(
pos
>
0
)
{
return
from
.
substring
(
pos
);
}
else
{
return
from
;
}
}
/**
/**
* 对比字符串是否相等,不区分大小写
* 对比字符串是否相等,不区分大小写
*
*
...
@@ -1177,40 +1135,102 @@ public class StringHelper {
...
@@ -1177,40 +1135,102 @@ public class StringHelper {
return
sb
.
toString
();
return
sb
.
toString
();
}
}
/**
/**
*
删除开头字符串
*
去掉两边的空格
*
*
* @param inStr
* @param from 需要去掉空格的字符串
* @param prefix
* @return 去掉字符串的值
*/
public
static
String
trim
(
String
from
)
{
if
(
from
==
null
)
{
return
EMPTY
;
}
return
from
.
trim
();
}
/**
* 去掉两边的空格
*
* @param from 需要去掉空格的字符串
* @return 去掉字符串的值
*/
public
static
String
trim
(
String
from
,
String
...
suffix
)
{
if
(
from
==
null
)
{
return
EMPTY
;
}
return
trimRight
(
trimLeft
(
from
,
suffix
),
suffix
);
}
/**
* 去掉左边的字符串
*
* @param from
* @param suffix
* @return
* @return
*/
*/
public
static
String
trimStart
(
String
inStr
,
String
prefix
)
{
public
static
String
trimLeft
(
String
from
,
String
...
suffix
)
{
if
(
inStr
==
null
)
{
if
(
from
==
null
)
{
return
null
;
return
EMPTY
;
}
boolean
handle
=
true
;
while
(
handle
)
{
handle
=
false
;
for
(
String
prefix
:
suffix
)
{
if
(
from
.
startsWith
(
prefix
))
{
from
=
from
.
substring
(
prefix
.
length
());
handle
=
true
;
}
}
if
(
inStr
.
startsWith
(
prefix
))
{
String
ret
=
inStr
.
substring
(
prefix
.
length
());
return
trimStart
(
ret
,
prefix
);
}
}
return
inStr
;
}
return
from
;
}
}
/**
/**
*
删除末尾
字符串
*
去掉左边的
字符串
*
*
* @param
inStr
* @param
from
* @param suffix
* @param suffix
* @return
* @return
*/
*/
public
static
String
trimEnd
(
String
inStr
,
String
suffix
)
{
public
static
String
trimRight
(
String
from
,
String
...
suffix
)
{
if
(
inStr
==
null
)
{
return
null
;
if
(
from
==
null
)
{
return
EMPTY
;
}
boolean
handle
=
true
;
while
(
handle
)
{
handle
=
false
;
for
(
String
prefix
:
suffix
)
{
if
(
from
.
endsWith
(
prefix
))
{
from
=
from
.
substring
(
0
,
from
.
length
()
-
prefix
.
length
());
handle
=
true
;
}
}
}
return
from
;
}
}
if
(
inStr
.
endsWith
(
suffix
))
{
String
ret
=
inStr
.
substring
(
0
,
inStr
.
length
()
-
suffix
.
length
());
/**
return
trimEnd
(
ret
,
suffix
);
* 删除开头字符串
*
* @param from
* @param suffix
* @return
*/
public
static
String
trimStart
(
String
from
,
String
...
suffix
)
{
return
trimLeft
(
from
,
suffix
);
}
}
return
inStr
;
/**
* 删除末尾字符串
*
* @param from
* @param suffix
* @return
*/
public
static
String
trimEnd
(
String
from
,
String
suffix
)
{
return
trimRight
(
from
,
suffix
);
}
}
}
}
yzg-util-base/src/test/java/helper/TestStringHelper.java
View file @
5a2d7d16
...
@@ -12,4 +12,13 @@ public class TestStringHelper {
...
@@ -12,4 +12,13 @@ public class TestStringHelper {
System
.
out
.
println
(
StringHelper
.
right
(
"03"
,
3
));
System
.
out
.
println
(
StringHelper
.
right
(
"03"
,
3
));
}
}
@Test
public
void
testTrim
()
{
System
.
out
.
println
(
StringHelper
.
trimLeft
(
"100500103"
,
"1"
,
"0"
));
System
.
out
.
println
(
StringHelper
.
trimRight
(
"100500103"
,
"3"
,
"0"
));
System
.
out
.
println
(
StringHelper
.
trim
(
"100500103"
,
"1"
,
"0"
,
"3"
));
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment