How to remove the first word from string in Scala

1 Answer

0 votes
object RemoveFirstWord {
  def trimFirstWord(input: String): String = {
    val pos = input.indexWhere(c => c == ' ' || c == '\t')
    
    if (pos != -1) input.substring(pos + 1) else input
  }

  def main(args: Array[String]): Unit = {
    val s = "c++ c c# java php scala"
    
    val result = trimFirstWord(s)
    
    println(result)
  }
}



/*
run:

c c# java php scala

*/

 



answered Sep 25 by avibootz
...