Scala String replace() method with example
Last Updated :
03 Oct, 2019
The replace() method is used to replace the old character of the string with the new one which is stated in the argument.
Method Definition: String replace(char oldChar, char newChar)
Return Type: It returns the stated string after replacing the old character with the new one.
Example #1:
object GfG
{
def main(args : Array[String])
{
val result = "Nidhi" .replace( 'N' , 'n' )
println(result)
}
}
|
Example #2:
object GfG
{
def main(args : Array[String])
{
val result = "Nidhi" .replace( 'h' , '#' )
println(result)
}
}
|
Share your thoughts in the comments
Please Login to comment...