github.com/enetx/g@v1.0.80/examples/strings.go (about)

     1  package main
     2  
     3  import (
     4  	"github.com/enetx/g"
     5  	"github.com/enetx/g/f"
     6  )
     7  
     8  func main() {
     9  	g.String("foo\r\nbar\n\nbaz\n").
    10  		Lines().
    11  		Exclude(f.Zero).
    12  		Collect().
    13  		Print() // Slice[foo, bar, baz]
    14  
    15  	s := g.NewString("๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ")
    16  
    17  	s.LeftJustify(10, "*").Print()  // ๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ******
    18  	s.RightJustify(10, "*").Print() // ******๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ
    19  	s.Center(10, "*").Print()       // ***๐Ÿ’›๐Ÿ’š๐Ÿ’™๐Ÿ’œ***
    20  
    21  	///////////////////////////////////////////////////////////////////////
    22  
    23  	ss := g.String("Hello, [world]! How [are] you?")
    24  
    25  	cuted := g.NewSlice[g.String]()
    26  
    27  	for ss.ContainsAll("[", "]") {
    28  		var cut g.String
    29  		ss, cut = ss.Cut("[", "]")
    30  		cuted.AppendInPlace(cut)
    31  	}
    32  
    33  	cuted.Print()
    34  
    35  	g.NewString(byte('g')).Print()
    36  	g.NewString(rune('g')).Print()
    37  	g.NewString([]rune("hello")).Print()
    38  	g.NewString([]byte("hello")).Print()
    39  
    40  	g.NewString("").Random(10).Print()
    41  	g.NewString("").Random(10, g.ASCII_LETTERS).Print()
    42  	g.NewString("").Random(10, g.DIGITS).Print()
    43  	g.NewString("").Random(10, g.PUNCTUATION).Print()
    44  
    45  	g.String("https://www.test.com/?query=Hellรถ Wรถrld&param=value").
    46  		Enc().
    47  		URL().
    48  		Print() // https://www.test.com/?query=Hell%C3%B6+W%C3%B6rld&param=value
    49  
    50  	g.String("Hellรถ Wรถrld@Golang").Enc().URL().Print()   // Hell%C3%B6+W%C3%B6rld@Golang
    51  	g.String("Hellรถ Wรถrld@Golang").Enc().URL("").Print() // Hell%C3%B6+W%C3%B6rld%40Golang
    52  
    53  	original := g.String("Hello, world! This is a test.")
    54  	modified := original.Remove(
    55  		"Hello",
    56  		"test",
    57  	)
    58  
    59  	modified.Print()
    60  }