gstring

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2022 License: MIT Imports: 8 Imported by: 0

README

字符串操作工具

工具加载

import (
	"github.com/cnlesscode/gotool/string"
)

FirstUpper(s string) string

函数功能 : 首字母大写 返回格式 : string

fmt.Printf("%v\n", gstring.FirstUpper("golang"))

FirstLower(s string) string

函数功能 : 首字母小写 返回格式 : string

fmt.Printf("%v\n", gstring.FirstLower("Golang"))

FindImagesFromHtml(html string) []string

函数功能 : 从 html 中匹配出图片 返回格式 : []string

html := `<div>...</div><img src="http://localhost/a.png" />`
images := gstring.FindImagesFromHtml(html)
fmt.Printf("images: %v\n", images)

TrimHtmlTags(html string) string

函数功能 : 去除 html 标签 返回格式 : string

html := `<div>...</div><img src="http://localhost/a.png" />`
html = gstring.TrimHtmlTags(html)
fmt.Printf("%v\n", html)

NLP 分词

字典位置 : "/resources/dict/zh/s_1.txt"
字典路径 : https://github.com/cnlesscode/gotool/tree/main/resources/dict
字典部署 : 请下载字典文件并部署到您的项目根目录 /resources 文件夹下
排除分词 : 您可以通过修改 /resources/dict/nplNotWords.txt 来排除不需要的分词

使用演示 :

package main
import (
	"fmt"
	"github.com/cnlesscode/gotool/gstring"
)
func main() {
	NLPObject := gstring.NLP{Content: "测试分词文本 : 测试分词频率"}
	words := NLPObject.Cut()
	fmt.Printf("words: %v\n", words)
}

AnyToString

函数功能 : 任意类型转字符串 返回格式 : string 使用演示 :

package main
import (
	"fmt"
	"github.com/cnlesscode/gotool/gstring"
)
func main() {
	a := 11
	aString := gstring.AnyToString(a)
	fmt.Printf("aString: %v\n", aString)
}

StripPunctuation

函数功能 : 去除标点符号 参数说明 : 一段字符串 返回格式 : string 使用演示 :

package main

import (
	"fmt"

	"github.com/cnlesscode/gotool/gstring"
)

func main() {
	str := "hi! 您好啊~ 。"
	str = gstring.StripPunctuation(str)
	fmt.Printf("str: %v\n", str)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AnyToString added in v1.0.8

func AnyToString(value interface{}) string

Any to string

func FindImagesFromHtml

func FindImagesFromHtml(html string) []string

Find Images From Html

func FirstLower

func FirstLower(s string) string

First Lower

func FirstUpper

func FirstUpper(s string) string

First Upper

func StripPunctuation added in v1.0.8

func StripPunctuation(str string) string

func TrimHtmlTags

func TrimHtmlTags(html string) string

Trim html tags

Types

type NLP

type NLP struct {
	Content string
}

func (*NLP) Cut

func (m *NLP) Cut() []NLPKwd

func (*NLP) SearchNLPKwd

func (m *NLP) SearchNLPKwd(slice []NLPKwd, str string) int

type NLPKwd

type NLPKwd struct {
	KeyWord string
	Count   int
}

Jump to

Keyboard shortcuts

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