Skip to content

Instantly share code, notes, and snippets.

@saml
Last active December 19, 2015 15:49
Show Gist options
  • Select an option

  • Save saml/5979158 to your computer and use it in GitHub Desktop.

Select an option

Save saml/5979158 to your computer and use it in GitHub Desktop.
def trim(s: String, c: Char): String = {
val prefixDropped: String = s.dropWhile(_ == c)
val lastNotC: Int = prefixDropped.lastIndexWhere(_ != c)
if (lastNotC == -1) prefixDropped
else prefixDropped.substring(0, lastNotC + 1)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment