-
-
Save Araglas88/d63242b1a1b215a48c2ef14332834ecb to your computer and use it in GitHub Desktop.
Scala-String-Functions.sc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str = "This is a String" | |
println( "The character at position 4th is " + str.charAt(3)) | |
output : The character at position 4th is s |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str = "abcDe" | |
str.compareTo("abCde") | |
str.compareTo("Bbcd") | |
str.compareTo("abcde") | |
res0: Int = 32 | |
res1: Int = 31 | |
res2: Int = -32 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str = "abcDe" | |
str.compareToIgnoreCase("AbcDe") | |
res0: Int = 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str = "Dave" | |
str.concat("Smith") | |
res0: String = DaveSmith | |
"Phil" + "Dunphy" | |
res1: String = PhilDunphy |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str = "subway" | |
str.contains("bwa") //res0: Boolean = true | |
str.contains("bWa") //res1: Boolean = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str1: String = "subway" | |
val str2: String = "subway" | |
str1.contentEquals(str2) //true | |
val str3: StringBuffer = new StringBuffer("subway") | |
str1.contentEquals(str3) //true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str1: String = "subway" | |
val str2: String = "way" | |
val str3: String = "wa" | |
str1.endsWith(str2) //true | |
str1.endsWith(str3) //false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str1: String = "subway" | |
val str2: String = "subway" | |
str1.equals(str2) //true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str1: String = "subway" | |
val str2: String = "SubWay" | |
str1.equalsIgnoreCase(str2) //true |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val str1: String = "subway" | |
str1.getBytes() | |
res0: Array[Byte] = Array(115, 117, 98, 119, 97, 121) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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