Skip to content

Instantly share code, notes, and snippets.

@aoiroaoino
Last active August 29, 2015 14:05
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 aoiroaoino/f93a75c63a68a5a4a374 to your computer and use it in GitHub Desktop.
Save aoiroaoino/f93a75c63a68a5a4a374 to your computer and use it in GitHub Desktop.
val table = Map( "%one%" -> "1", "%two%" -> "2", "%three%" -> "3" )
// ↓もっとカッコ良く書けないかな??
def replaceSpecialWords(target: String) = {
var str = target
table.keys.foreach { key =>
str = str.replaceAll(key, table(key))
}
str
}
@aoiroaoino
Copy link
Author

ループ内で呼ばれる想定のメソッドだからtable.keysを何回もまわしたくない

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment