Skip to content

Instantly share code, notes, and snippets.

@karakanb
Created December 15, 2020 17:56
Show Gist options
  • Save karakanb/30ec436da6537c6ceb33f18b2923564c to your computer and use it in GitHub Desktop.
Save karakanb/30ec436da6537c6ceb33f18b2923564c to your computer and use it in GitHub Desktop.
func parseWithReplaceAll(inputString string) int {
isAm := strings.HasSuffix(inputString, "AM")
if isAm {
inputString = strings.ReplaceAll(inputString, "AM", "")
} else {
inputString = strings.ReplaceAll(inputString, "PM", "")
}
number, _ := strconv.Atoi(inputString)
if !isAm {
number += 12
}
return number
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment