mirror of
https://github.com/duke-git/lancet.git
synced 2026-02-14 01:32:27 +08:00
doc: add doc for RemoveWhiteSpace
This commit is contained in:
@@ -58,6 +58,7 @@ import (
|
|||||||
- [HideString](#HideString)
|
- [HideString](#HideString)
|
||||||
- [ContainsAll](#ContainsAll)
|
- [ContainsAll](#ContainsAll)
|
||||||
- [ContainsAny](#ContainsAny)
|
- [ContainsAny](#ContainsAny)
|
||||||
|
- [RemoveWhiteSpace](#RemoveWhiteSpace)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -1390,3 +1391,37 @@ func main() {
|
|||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
### <span id="RemoveWhiteSpace">RemoveWhiteSpace</span>
|
||||||
|
|
||||||
|
<p>Remove whitespace characters from a string. when set repalceAll is true removes all whitespace, false only replaces consecutive whitespace characters with one space.</p>
|
||||||
|
|
||||||
|
<b>Signature:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func RemoveWhiteSpace(str string, repalceAll bool) string
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>Example:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/strutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
str := " hello \r\n \t world"
|
||||||
|
|
||||||
|
result1 := strutil.RemoveWhiteSpace(str, true)
|
||||||
|
result2 := strutil.RemoveWhiteSpace(str, false)
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// helloworld
|
||||||
|
// hello world
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ import (
|
|||||||
- [HideString](#HideString)
|
- [HideString](#HideString)
|
||||||
- [ContainsAll](#ContainsAll)
|
- [ContainsAll](#ContainsAll)
|
||||||
- [ContainsAny](#ContainsAny)
|
- [ContainsAny](#ContainsAny)
|
||||||
|
- [RemoveWhiteSpace](#RemoveWhiteSpace)
|
||||||
|
|
||||||
<div STYLE="page-break-after: always;"></div>
|
<div STYLE="page-break-after: always;"></div>
|
||||||
|
|
||||||
@@ -975,7 +975,7 @@ func main() {
|
|||||||
|
|
||||||
fmt.Println(result1)
|
fmt.Println(result1)
|
||||||
fmt.Println(result2)
|
fmt.Println(result2)
|
||||||
|
|
||||||
// Output:
|
// Output:
|
||||||
// hello world
|
// hello world
|
||||||
// 你好😄
|
// 你好😄
|
||||||
@@ -1179,7 +1179,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="ReplaceWithMap">ReplaceWithMap</span>
|
### <span id="ReplaceWithMap">ReplaceWithMap</span>
|
||||||
|
|
||||||
<p>返回`str`的副本,以无序的方式被map替换,区分大小写。</p>
|
<p>返回`str`的副本,以无序的方式被map替换,区分大小写。</p>
|
||||||
@@ -1250,7 +1249,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="SplitAndTrim">SplitAndTrim</span>
|
### <span id="SplitAndTrim">SplitAndTrim</span>
|
||||||
|
|
||||||
<p>将字符串str按字符串delimiter拆分为一个切片,并对该数组的每个元素调用Trim。忽略Trim后为空的元素。</p>
|
<p>将字符串str按字符串delimiter拆分为一个切片,并对该数组的每个元素调用Trim。忽略Trim后为空的元素。</p>
|
||||||
@@ -1284,7 +1282,6 @@ func main() {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
### <span id="HideString">HideString</span>
|
### <span id="HideString">HideString</span>
|
||||||
|
|
||||||
<p>使用参数`replaceChar`隐藏源字符串中的一些字符。替换范围是 origin[start : end]。</p>
|
<p>使用参数`replaceChar`隐藏源字符串中的一些字符。替换范围是 origin[start : end]。</p>
|
||||||
@@ -1392,3 +1389,36 @@ func main() {
|
|||||||
// false
|
// false
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### <span id="RemoveWhiteSpace">RemoveWhiteSpace</span>
|
||||||
|
|
||||||
|
<p>删除字符串中的空格,当设置repalceAll为true时,删除全部空格,为false时,替换多个空格为1个空格。</p>
|
||||||
|
|
||||||
|
<b>函数签名:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
func RemoveWhiteSpace(str string, repalceAll bool) string
|
||||||
|
```
|
||||||
|
|
||||||
|
<b>示例:</b>
|
||||||
|
|
||||||
|
```go
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/duke-git/lancet/v2/strutil"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
str := " hello \r\n \t world"
|
||||||
|
|
||||||
|
result1 := strutil.RemoveWhiteSpace(str, true)
|
||||||
|
result2 := strutil.RemoveWhiteSpace(str, false)
|
||||||
|
|
||||||
|
fmt.Println(result1)
|
||||||
|
fmt.Println(result2)
|
||||||
|
|
||||||
|
// Output:
|
||||||
|
// helloworld
|
||||||
|
// hello world
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|||||||
Reference in New Issue
Block a user