This page is no longer maintained — Please continue to the home page at www.scala-lang.org

REPL hates "."s

2 replies
Meredith Gregory
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Dear Scalarazzi,
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).Type in expressions to have them evaluated. Type :help for more information.
scala> val s1 = "my.string.has.dots.in.it" val s1 = "my.string.has.dots.in.it"s1: java.lang.String = my.string.has.dots.in.it
scala> s1.split( "." )s1.split( "." ) res0: Array[java.lang.String] = Array()
scala> val s2 = "my-string-has-dashes-in-it" val s2 = "my-string-has-dashes-in-it"s2: java.lang.String = my-string-has-dashes-in-it
scala> s2.split( "-" )s2.split( "-" ) res1: Array[java.lang.String] = Array(my, string, has, dashes, in, it)
scala> 
Best wishes,
--greg

--
L.G. Meredith
Managing Partner
Biosimilarity LLC
7329 39th Ave SWSeattle, WA 98136

+1 206.650.3740

http://biosimilarity.blogspot.com
Meredith Gregory
Joined: 2008-12-17,
User offline. Last seen 42 years 45 weeks ago.
Re: REPL hates "."s
P.S. Apologies -- i see that split is internally using regex and "." is interpreted as a meta-character. Escaping does the trick.

On Mon, Jan 2, 2012 at 11:35 PM, Meredith Gregory <lgreg [dot] meredith [at] gmail [dot] com> wrote:
Dear Scalarazzi,
Welcome to Scala version 2.9.0.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29). Type in expressions to have them evaluated. Type :help for more information.
scala> val s1 = "my.string.has.dots.in.it" val s1 = "my.string.has.dots.in.it"s1: java.lang.String = my.string.has.dots.in.it
scala> s1.split( "." )s1.split( "." ) res0: Array[java.lang.String] = Array()
scala> val s2 = "my-string-has-dashes-in-it" val s2 = "my-string-has-dashes-in-it"s2: java.lang.String = my-string-has-dashes-in-it
scala> s2.split( "-" )s2.split( "-" ) res1: Array[java.lang.String] = Array(my, string, has, dashes, in, it)
scala> 
Best wishes,
--greg

--
L.G. Meredith
Managing Partner
Biosimilarity LLC
7329 39th Ave SW Seattle, WA 98136

+1 206.650.3740

http://biosimilarity.blogspot.com



--
L.G. Meredith
Managing Partner
Biosimilarity LLC
7329 39th Ave SWSeattle, WA 98136

+1 206.650.3740

http://biosimilarity.blogspot.com
Stefan Wagner
Joined: 2011-04-08,
User offline. Last seen 42 years 45 weeks ago.
Re: Re: REPL hates "."s

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Am 03.01.2012 08:37, schrieb Meredith Gregory:
> P.S. Apologies -- i see that split is internally using regex and "." is
> interpreted as a meta-character. Escaping does the trick.

Or using a char as delimiter:

scala> val s1 = "my.string.has.dots.in.it".split ('.')
s1: Array[String] = Array(my, string, has, dots, in, it)

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland