gstrings

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2025 License: MIT Imports: 3 Imported by: 0

README

gstrings 包

简介

gstrings 包提供了字符串处理相关的工具函数。

功能特性

  • 字符串转换:各种格式转换
  • 字符串处理:分割、连接、替换
  • 随机字符串:生成随机字符串
  • 编码解码:Base64、URL 编码等

安装

go get github.com/snail007/gmc/util/strings

快速开始

package main

import (
    "fmt"
    "github.com/snail007/gmc/util/strings"
)

func main() {
    // 驼峰转下划线
    snake := gstrings.CamelToSnake("HelloWorld")
    fmt.Println(snake) // hello_world
    
    // 下划线转驼峰
    camel := gstrings.SnakeToCamel("hello_world")
    fmt.Println(camel) // HelloWorld
    
    // 首字母大写
    title := gstrings.Title("hello")
    fmt.Println(title) // Hello
    
    // 首字母小写
    lower := gstrings.Untitle("Hello")
    fmt.Println(lower) // hello
}

API 参考

  • CamelToSnake(s) string:驼峰转下划线
  • SnakeToCamel(s) string:下划线转驼峰
  • Title(s) string:首字母大写
  • Untitle(s) string:首字母小写
  • Random(n) string:随机字符串
  • Contains(s, substr) bool:是否包含子串
  • HasPrefix(s, prefix) bool:是否有前缀
  • HasSuffix(s, suffix) bool:是否有后缀

相关链接

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesToString

func BytesToString(b []byte) string

func ContainsAll

func ContainsAll(str string, sub ...string) bool

func ContainsAny

func ContainsAny(str string, sub ...string) bool

func HasHTTPPrefix

func HasHTTPPrefix(str string) bool

func HasPrefixAny

func HasPrefixAny(str string, prefix ...string) bool

func HasSuffixAny

func HasSuffixAny(str string, suffix ...string) bool

func Render

func Render(str string, data map[string]string) string

Render replaces ${var} or $var in the string based on the mapping data, 'var' is key in data map.

func Replace

func Replace(str string, oldNew ...string) string

Replace str from a list of old, new string pairs. Replacements are performed in the order they appear in the target string, without overlapping matches. The old string comparisons are done in argument order.

Replace panics if given an odd number of oldNew arguments.

func StringToBytes

func StringToBytes(s string) []byte

Types

This section is empty.

Jump to

Keyboard shortcuts

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