strings

package
v1.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2020 License: MIT Imports: 3 Imported by: 1

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Strings

type Strings []string

Strings 定义方便操作[]string的类型

Example
package main

import (
	"fmt"

	"github.com/recallsong/go-utils/container/slice/strings"
)

func main() {
	s := strings.Strings{}
	s.Append("abc", "abcd")
	s.Prepend("123", "456", "1234")
	s.Insert(1, "efg", "12")
	fmt.Println(s, s.Len())

	s1 := s.Copy()
	removed := s1.Remove(1, 1)
	fmt.Println(s1, s1.Len(), removed)
}
Output:

[123 efg 12 456 1234 abc abcd] 7
[123 12 456 1234 abc abcd] 6 1
Example (Order)
package main

import (
	"fmt"

	"github.com/recallsong/go-utils/container/slice/strings"
)

func main() {
	s := strings.Strings{}
	s.Append("5", "4", "6", "3", "1", "2")
	s.Sort()
	fmt.Println(s)
	s.ReverseSort()
	fmt.Println(s)

	s.Shuffle() //随机打乱数据
	// fmt.Println(s)

}
Output:

[1 2 3 4 5 6]
[6 5 4 3 2 1]

func (*Strings) Append

func (s *Strings) Append(data ...string)

Append 追加数据

func (Strings) Cap

func (s Strings) Cap() int

Cap 返回slice容量

func (Strings) Copy

func (s Strings) Copy() Strings

Copy 拷贝一份数据

func (*Strings) Insert

func (s *Strings) Insert(index int, data ...string)

Insert 插入数据

func (Strings) Join

func (s Strings) Join(sep string) string

Join 将多个字符串连接

func (Strings) Len

func (s Strings) Len() int

Len 返回slice长度

func (Strings) Less

func (s Strings) Less(i, j int) bool

Less 比较两个位置上的数据

func (*Strings) Prepend

func (s *Strings) Prepend(data ...string)

Prepend 向前添加数据

func (*Strings) Remove

func (s *Strings) Remove(index, num int) int

Remove 从指定位置删除指定数量的数据,返回被删除的数据数量

func (Strings) ReverseSort

func (s Strings) ReverseSort() Strings

func (Strings) Shuffle

func (s Strings) Shuffle() Strings

Shuffle 随机打乱slice数据

func (Strings) Sort

func (s Strings) Sort() Strings

Sort 对切片进行排序

func (Strings) Swap

func (s Strings) Swap(i, j int)

Swap 交换两个位置上的数据

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL