带有示例的 Scala String trim() 方法
trim()方法用于省略指定字符串中的前导和尾随空格。
Method Definition: String trim()
Return Type: It returns the stated string after removing all the white spaces.
示例:1#
// Scala program of trim()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying trim method
val result = " Nidhi Singh ".trim()
// Displays output
println(result)
}
}
输出:
Nidhi Singh
示例:2#
// Scala program of trim()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying trim method
val result = " Nidhi Singh GfG ".trim()
// Displays output
println(result)
}
}
输出:
Nidhi Singh GfG