带有示例的 Scala String substring() 方法
substring()方法用于从指定的索引开始的指定字符串中查找子字符串。
Method Definition: String substring(int beginIndex)
Return Type: It returns the content from the given String Which starts from the index we specify.
示例:1#
// Scala program of substring()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying substring method
val result = "GeeksforGeeks".substring(8)
// Displays output
println(result)
}
}
输出:
Geeks
示例:2#
// Scala program of substring()
// method
// Creating object
object GfG
{
// Main method
def main(args:Array[String])
{
// Applying substring method
val result = "GeeksforGeeks".substring(11)
// Displays output
println(result)
}
}
输出:
ks