Skip to content

Instantly share code, notes, and snippets.

@genghisjahn
Created February 9, 2015 03:53
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 genghisjahn/40e900ce285a2100f000 to your computer and use it in GitHub Desktop.
Save genghisjahn/40e900ce285a2100f000 to your computer and use it in GitHub Desktop.
TextLengthDemo
func ProcessText(text string, items []TextLengthItem) string {
firstParts := []string{"This text is %v characters in length.", "Text is %v characters long.", "Text is %v characters in length."}
result_template := "%v %v"
textLength := len(text) + 2
for _, firstPart := range firstParts {
for _, item := range items {
length_sentence := fmt.Sprintf(firstPart, item.Text)
if textLength+len(length_sentence) == item.Value {
return fmt.Sprintf(result_template, text, length_sentence)
}
}
}
return "No match found."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment