Last active
December 28, 2015 15:58
-
-
Save aembleton/7525124 to your computer and use it in GitHub Desktop.
Implict String Utilities
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
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