Skip to content

Instantly share code, notes, and snippets.

@Araglas88
Last active October 18, 2021 12:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Araglas88/d63242b1a1b215a48c2ef14332834ecb to your computer and use it in GitHub Desktop.
Save Araglas88/d63242b1a1b215a48c2ef14332834ecb to your computer and use it in GitHub Desktop.
Scala-String-Functions.sc
val str = "This is a String"
println( "The character at position 4th is " + str.charAt(3))
output : The character at position 4th is s
val str = "This is a String"
println( "The UTF-16 value of 4th character is " + str.codePointAt(3))
The UTF-16 value of 4th character is 115
val str = "abcDe"
str.compareTo("abCde")
str.compareTo("Bbcd")
str.compareTo("abcde")
res0: Int = 32
res1: Int = 31
res2: Int = -32
val str = "abcDe"
str.compareToIgnoreCase("AbcDe")
res0: Int = 0
val str = "Dave"
str.concat("Smith")
res0: String = DaveSmith
"Phil" + "Dunphy"
res1: String = PhilDunphy
val str = "subway"
str.contains("bwa") //res0: Boolean = true
str.contains("bWa") //res1: Boolean = false
val str1: String = "subway"
val str2: String = "subway"
str1.contentEquals(str2) //true
val str3: StringBuffer = new StringBuffer("subway")
str1.contentEquals(str3) //true
val str1: String = "subway"
val str2: String = "way"
val str3: String = "wa"
str1.endsWith(str2) //true
str1.endsWith(str3) //false
val str1: String = "subway"
val str2: String = "subway"
str1.equals(str2) //true
val str1: String = "subway"
val str2: String = "SubWay"
str1.equalsIgnoreCase(str2) //true
val str1: String = "subway"
str1.getBytes()
res0: Array[Byte] = Array(115, 117, 98, 119, 97, 121)
Here we have listed down all the Scala String Functions with example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment