Difference between revisions of "String Operations"

From mi-linux
Jump to navigationJump to search
(New page: == Really, really, long strings == Instead of using '''"''' you can use '''"""''' as a string delimeter if you want to define a really, really long string that is split over several lines...)
 
m
Line 1: Line 1:
 
== Really, really, long strings ==
 
== Really, really, long strings ==
  
Instead of using '''"''' you can use '''"""''' as a string delimeter if you want to define a really, really long string that is split over several lines. Like this:
+
Instead of using '''"''' you can use '''"""''' (three double quote marks) as a string delimeter if you want to define a really, really long string that is split over several lines. Like this:
  
 
   <nowiki>
 
   <nowiki>

Revision as of 01:16, 21 February 2011

Really, really, long strings

Instead of using " you can use """ (three double quote marks) as a string delimeter if you want to define a really, really long string that is split over several lines. Like this:

 
val really_long_string = """<html>
  <head>
    <title>Looooong Scala String</title>
  </head>
  <body>
    <h1>This is a very long string indeed!</h1>
  </body>
</html>"""
println(really_long_string)
  

Splitting strings

 
scala> val mystring = "Hello, I like Scala! It, does, rock."
mystring: java.lang.String = Hello, I like Scala! It, does, rock.


scala> mystring.split(",")
res0: Array[java.lang.String] = Array(Hello,  I like Scala! It,  does,  rock.)


scala> mystring.split(",").foreach((msg:String) => println(msg))
Hello
 I like Scala! It
 does
 rock.

scala>