How to calculate string length without spaces in Scala

1 Answer

0 votes
val str = "The Scala Programming Language"

val lengthWithoutSpaces = str.filter(_ != ' ').length

println(lengthWithoutSpaces)

  
  
/*
run:
    
27
  
*/

 



answered Jan 11, 2025 by avibootz
...