How to move the digits of a string with digits and letters to the beginning of the string in Scala

1 Answer

0 votes
def moveDigitsToFront(input: String): String = {
  val (digits, others) = input.partition(_.isDigit)
  digits + others
}


var str = "d2a54be3c1"
str = moveDigitsToFront(str)

println(str) 



 
/*
run:

25431dabec

*/

 



answered May 27, 2025 by avibootz
...