Scala Converting multiline string to BigInt

前端 未结 1 1742
暗喜
暗喜 2021-01-19 06:37

I\'m trying to parse 100 50-digit numbers from string with below piece of code:

val input = \"\"\"37107287533902102798797998220837590246510135740250
                 


        
相关标签:
1条回答
  • 2021-01-19 06:49

    Probably you're on Windows, where the EOL is \r\n.

    You've got to strip that, too.

    Here, I rebooted into Windows to demo...

    apm@halyard ~/tmp
    $ vi bigbomb.scala
    
    apm@halyard ~/tmp
    $ skalac bigbomb.scala ; skala bigbomb.Test
    "ava.lang.NumberFormatException: For input string: "35740250
            at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
    

    Note that in cygwin, I have to :se fileformat=dos in vi to use the \r\n line endings.

    Here is an example where the unacknowledged impedance mismatch between the source EOL and the runtime EOL bugged me:

    some dumb code

    You want to use s.lines.mkString to strip it out.

    0 讨论(0)
提交回复
热议问题