Skip to content
/ cleaner Public

Go package for composing functions to clean strings

License

Notifications You must be signed in to change notification settings

dnlo/cleaner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Package for cleaning strings

Go Report Card

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))
	}
}

About

Go package for composing functions to clean strings

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages