Skip to content

Instantly share code, notes, and snippets.

@17twenty
Created September 29, 2022 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 17twenty/8ef23630978341a4e5c59ef28374fb8d to your computer and use it in GitHub Desktop.
Save 17twenty/8ef23630978341a4e5c59ef28374fb8d to your computer and use it in GitHub Desktop.
Clean and simplify a user entered name to make a Stripe 22 character friendly merchant name
package main
import (
"fmt"
"regexp"
"strings"
)
var re *regexp.Regexp
func init() {
re = regexp.MustCompile(`[^\w]`)
}
func BankFriendlyReceipt(str string) string {
str = re.ReplaceAllString(str, "")
str = strings.Title(str)
str = strings.Replace(str, " ", "", -1)
return string("FW*" + str)[:22]
}
func main() {
merchantName := "Lawrence's &@$*(& Legal Services"
fmt.Println(merchantName)
fmt.Println(BankFriendlyReceipt(merchantName), "is", len(BankFriendlyReceipt(merchantName)), "characters long")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment