Created
February 9, 2015 03:53
-
-
Save genghisjahn/40e900ce285a2100f000 to your computer and use it in GitHub Desktop.
TextLengthDemo
This file contains hidden or 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
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