https://github.com/dnlo/cleaner
Go package for composing functions to clean strings
https://github.com/dnlo/cleaner
cleaner go strings-manipulation
Last synced: 5 months ago
JSON representation
Go package for composing functions to clean strings
- Host: GitHub
- URL: https://github.com/dnlo/cleaner
- Owner: dnlo
- License: mit
- Created: 2018-10-20T09:45:27.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-11-18T13:05:24.000Z (over 7 years ago)
- Last Synced: 2024-06-20T08:04:13.362Z (about 2 years ago)
- Topics: cleaner, go, strings-manipulation
- Language: Go
- Size: 6.84 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Package for cleaning strings
[](https://goreportcard.com/report/github.com/dnlo/cleaner)
Docs: https://godoc.org/github.com/dnlo/cleaner
Example:
```
package main
import (
"fmt"
"github.com/dnlo/cleaner"
)
var sellers = []string{
"Seller: 3*3whiteangel3*3(1,175) 100%",
"Seller: 80vann(545) 100%",
"Seller: accessman4(1,010) 97.3%",
"Seller: a_clothingdipity(1,403) 100% View seller's store: a_clothingdipity",
"Seller: andrewandania(11,405) 100% View seller's store: andrewandania",
}
type seller struct {
Name string
Sales string
Feedback string
}
func extract(s string) seller {
getName := cleaner.Clean(
cleaner.AfterLast("Seller: "),
cleaner.BeforeFirst(`(`))
getSales := cleaner.Clean(
cleaner.AfterLast("("),
cleaner.BeforeFirst(")"),
cleaner.Delete(","))
getFeedback := cleaner.Clean(
cleaner.AfterLast(") "),
cleaner.Delete("%"),
cleaner.Extract(`[0-9\.]*`))
return seller{
Name: getName(s),
Sales: getSales(s),
Feedback: getFeedback(s),
}
}
func main() {
for _, v := range sellers {
fmt.Println(extract(v))
}
}
```