stringy/example/main.go

90 lines
2.7 KiB
Go
Raw Normal View History

2020-04-03 06:36:09 +03:00
package main
import (
"fmt"
2023-01-20 08:17:29 +03:00
2020-07-17 11:32:40 +03:00
"github.com/gobeam/stringy"
2020-04-03 06:36:09 +03:00
)
func main() {
2020-04-05 16:10:08 +03:00
strBetween := stringy.New("HelloMyName")
2020-04-05 14:02:47 +03:00
fmt.Println(strBetween.Between("hello", "name").ToUpper())
2020-04-05 12:11:56 +03:00
2020-04-05 16:10:08 +03:00
teaseString := stringy.New("Hello My name is Roshan. I am full stack developer")
2020-04-05 15:57:30 +03:00
fmt.Println(teaseString.Tease(20, "..."))
2020-04-05 12:11:56 +03:00
2020-04-05 16:10:08 +03:00
replaceFirst := stringy.New("Hello My name is Roshan and his name is Alis.")
2020-04-05 12:11:56 +03:00
fmt.Println(replaceFirst.ReplaceFirst("name", "nombre"))
2020-04-05 16:10:08 +03:00
replaceLast := stringy.New("Hello My name is Roshan and his name is Alis.")
2020-04-05 12:11:56 +03:00
fmt.Println(replaceLast.ReplaceLast("name", "nombre"))
2020-04-05 16:10:08 +03:00
snakeCase := stringy.New("ThisIsOne___messed up string. Can we Really Snake Case It?")
2020-04-05 14:02:47 +03:00
fmt.Println(snakeCase.SnakeCase("?", "").Get())
2020-04-05 15:57:30 +03:00
fmt.Println(snakeCase.SnakeCase("?", "").ToUpper())
fmt.Println(snakeCase.SnakeCase("?", "").ToLower())
2020-04-05 12:11:56 +03:00
2020-04-05 16:10:08 +03:00
camelCase := stringy.New("ThisIsOne___messed up string. Can we Really camel-case It ?##")
2024-03-16 13:19:07 +03:00
fmt.Println(camelCase.CamelCase("?", "", "#", "").Get())
2020-04-05 12:11:56 +03:00
2020-04-05 16:10:08 +03:00
delimiterString := stringy.New("ThisIsOne___messed up string. Can we Really delimeter-case It?")
2020-04-05 12:11:56 +03:00
fmt.Println(delimiterString.Delimited("?").Get())
2020-04-05 16:10:08 +03:00
contains := stringy.New("hello mam how are you??")
2020-04-05 14:02:47 +03:00
fmt.Println(contains.ContainsAll("mams", "?"))
2020-04-05 12:11:56 +03:00
2020-04-05 16:10:08 +03:00
lines := stringy.New("fòô\r\nbàř\nyolo123")
2020-04-05 12:11:56 +03:00
fmt.Println(lines.Lines())
2020-04-05 16:10:08 +03:00
reverse := stringy.New("This is only test")
2020-04-05 12:11:56 +03:00
fmt.Println(reverse.Reverse())
2020-04-03 06:36:09 +03:00
2020-04-05 16:10:08 +03:00
pad := stringy.New("Roshan")
2020-04-05 15:57:30 +03:00
fmt.Println(pad.Pad(10, "0", "both"))
fmt.Println(pad.Pad(10, "0", "left"))
fmt.Println(pad.Pad(10, "0", "right"))
2020-04-03 06:36:09 +03:00
2020-04-05 16:10:08 +03:00
shuffleString := stringy.New("roshan")
2020-04-05 12:11:56 +03:00
fmt.Println(shuffleString.Shuffle())
2020-04-03 06:36:09 +03:00
2020-04-05 16:10:08 +03:00
cleanString := stringy.New("special@#remove%%%%")
2020-04-05 12:11:56 +03:00
fmt.Println(cleanString.RemoveSpecialCharacter())
2020-04-03 06:36:09 +03:00
2020-04-05 16:10:08 +03:00
boolString := stringy.New("off")
2020-04-05 12:11:56 +03:00
fmt.Println(boolString.Boolean())
2020-04-03 06:36:09 +03:00
2020-04-05 16:10:08 +03:00
surroundStr := stringy.New("__")
2020-04-05 15:57:30 +03:00
fmt.Println(surroundStr.Surround("-"))
2020-04-05 16:10:08 +03:00
str := stringy.New("hello__man how-Are you??")
2024-03-16 13:19:07 +03:00
result := str.CamelCase("?", "").Get()
2020-04-05 15:57:30 +03:00
fmt.Println(result) // HelloManHowAreYou
snakeStr := str.SnakeCase("?", "")
fmt.Println(snakeStr.ToLower()) // hello_man_how_are_you
kebabStr := str.KebabCase("?", "")
fmt.Println(kebabStr.ToUpper()) // HELLO-MAN-HOW-ARE-YOU
fcn := stringy.New("4111 1111 1111 1111")
first := fcn.First(4)
fmt.Println(first) // 4111
lcn := stringy.New("4111 1111 1111 1348")
last := lcn.Last(4)
fmt.Println(last) // 1348
ufo := stringy.New("known flying object")
fmt.Println(ufo.Prefix("un")) // unknown flying object
pun := stringy.New("this really is a cliff")
fmt.Println(pun.Suffix("hanger")) // this really is a cliffhanger
2023-01-20 08:17:29 +03:00
acronym := stringy.New("Laugh Out Loud")
fmt.Println(acronym.Acronym().ToLower()) // lol
2023-01-20 14:29:12 +03:00
title := stringy.New("this is just AN eXample")
fmt.Println(title.Title()) // This Is Just An Example
2020-04-05 12:11:56 +03:00
}