Themerius
Themerius

Reputation: 1911

String diffs as List

Given:

val foo = "123456"
val bar = "24"

Now make diffs of this strings:

foo diff bar
// String = 1356

This returns the differences as concatenated String. Is it possible to get a List of the diffs? Something like:

foo magicDiff bar
// List[String] = List("1", "3", "56")

Upvotes: 2

Views: 91

Answers (1)

Marth
Marth

Reputation: 24812

scala> foo.split(bar.toArray).toList.filterNot(_.isEmpty)
res0: List[String] = List(1, 3, 56)

Upvotes: 2

Related Questions