📜  带有示例的 Scala String charAt() 方法

📅  最后修改于: 2022-05-13 01:54:44.337000             🧑  作者: Mango

带有示例的 Scala String charAt() 方法

charAt()方法用于返回参数中传递的索引的字符。

示例 #1:

// Scala program of charAt()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1 = "Nidhi"
          
        // Applying charAt() method
        val result = m1.charAt(2)
          
        // Displays output
        println(result)
          
    }
} 
输出:
d

示例 #2:

// Scala program of charAt()
// method
  
// Creating object
object GfG
{ 
  
    // Main method
    def main(args:Array[String])
    {
        // Creating a String
        val m1 = "Nidhi"
          
        // Applying charAt() method
        val result = m1.charAt(0)
          
        // Displays output
        println(result)
          
    }
} 
输出:
N