gostringsplus

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2019 License: MIT Imports: 3 Imported by: 1

README

gostringsplus

Build Status Go Report Card MIT

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)
    // 😎🌈🌈
}

Licence, credit & sponsorship

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!

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLeft

func GetLeft(value string, length int) (string, error)

GetLeft returns the given length of the left-most characters.

func GetRight

func GetRight(value string, length int) (string, error)

GetRight returns the given length of the right-most characters.

func ReplaceStart

func ReplaceStart(value string, prefix string) (string, error)

ReplaceStart replaces the start of a string with a new prefix.

Types

This section is empty.

Jump to

Keyboard shortcuts

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