gostringsplus

A Golang package providing string functions I find useful.
Non-English characters including emoji are supported.
GetLeft
GetLeft returns the left-most characters in a string.
package main
import (
"fmt"
"github.com/cariad/gostringsplus"
)
func main() {
hello, _ := gostringsplus.GetLeft("hello", 2)
fmt.Println(hello)
// he
utf8, _ := gostringsplus.GetLeft("日a本b語", 2)
fmt.Println(utf8)
// 日a
emoji, _ := gostringsplus.GetLeft("😎🌈🌈", 2)
fmt.Println(emoji)
// 😎🌈
}
GetRight
GetRight returns the right-most characters in a string.
package main
import (
"fmt"
"github.com/cariad/gostringsplus"
)
func main() {
hello, _ := gostringsplus.GetRight("hello", 2)
fmt.Println(hello)
// lo
utf8, _ := gostringsplus.GetRight("日a本b語", 2)
fmt.Println(utf8)
// b語
emoji, _ := gostringsplus.GetRight("😎🌈🌈", 2)
fmt.Println(emoji)
// 🌈🌈
}
ReplaceStart
ReplaceStart replaces the start of a string with a new set of runes.
package main
import (
"fmt"
"github.com/cariad/gostringsplus"
)
func main() {
hello, _ := gostringsplus.ReplaceStart("hello", "bu")
fmt.Println(hello)
// bullo
utf8, _ := gostringsplus.ReplaceStart("日a本b語", "ç")
fmt.Println(utf8)
// ça本b語
emoji, _ := gostringsplus.ReplaceStart("🌈🌈🌈", "😎")
fmt.Println(emoji)
// 😎🌈🌈
}
This project is published under the MIT Licence.
You don't owe me anything in return, but as an indie freelance coder there are two things I'd appreciate:
- Credit. If your app or documentation has a credits page, please consider mentioning the projects you use.
- Cash. If you want and are able to support future development, please consider becoming a patron or buying me a coffee. Thank you!