Skip to content

Instantly share code, notes, and snippets.

@aembleton
Last active December 28, 2015 15:58
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 aembleton/7525124 to your computer and use it in GitHub Desktop.
Save aembleton/7525124 to your computer and use it in GitHub Desktop.
Implict String Utilities
package util
/**
* Created with IntelliJ IDEA.
* User: arthur
* Date: 17/11/13
* Time: 22:26
* To change this template use File | Settings | File Templates.
*/
object StringUtils {
implicit class StringImprovements(val s: String) {
import scala.util.control.Exception._
def toIntOpt = catching(classOf[NumberFormatException]) opt s.toInt
def toIntOrElse(e:Int):Int = toIntOpt match {
case Some(x) => x
case None => e
}
def normalise = s.toLowerCase().split(" ").map(_.trim.capitalize).mkString(" ")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment