Q:

Write a Scala program to get a substring of a given string between two specified positions

0

Write a Scala program to get a substring of a given string between two specified positions.

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

object Scala_String {
  def main(args: Array[String]): Unit = {
    val str = "The quick brown fox jumps over the lazy dog.";

    // Get a substring of the above string starting from
    // index 10 and ending at index 26.
    val new_str = str.substring(10, 26);

    // Display the two strings for comparison.
    println("Original = " + str);
    println("From said string, substring between two positions (10,26) = " + new_str);

  }
}

Sample Output:

Original = The quick brown fox jumps over the lazy dog.
From said string, substring between two positions (10,26) = brown fox jumps

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now