Created
September 29, 2022 02:49
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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