W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗值獎勵
Levenshtein
?計算兩個字符串之間的?Levenshtein
?距離。
Levenshtein(str1, str2 string, costIns, costRep, costDel int) int
func ExampleLevenshtein() {
var (
str1 = "Hello World"
str2 = "hallo World"
costIns = 1
costRep = 1
costDel = 1
result = gstr.Levenshtein(str1, str2, costIns, costRep, costDel)
)
fmt.Println(result)
// Output:
// 2
}
SimilarText
?計算兩個字符串之間的相似度。
SimilarText(first, second string, percent *float64) int
func ExampleSimilarText() {
var (
first = `AaBbCcDd`
second = `ad`
percent = 0.80
result = gstr.SimilarText(first, second, &percent)
)
fmt.Println(result)
// Output:
// 2
}
Soundex
?用于計算字符串的?Soundex
?鍵。
Soundex(str string) string
func ExampleSoundex() {
var (
str1 = `Hello`
str2 = `Hallo`
result1 = gstr.Soundex(str1)
result2 = gstr.Soundex(str2)
)
fmt.Println(result1, result2)
// Output:
// H400 H400
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報電話:173-0602-2364|舉報郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: