स्कैला 2.10.0-आरसी 1 का उपयोग करके, मैंने विंडोज फ़ाइल पथ के अंदर स्ट्रिंग इंटरपोलेशन का उपयोग करने की कोशिश की, उदाहरण के लिए इस तरह:क्या यह बैकलस्लैश के साथ एक मल्टीलाइन स्ट्रिंग के अंदर स्कैला 2.10 स्ट्रिंग इंटरपोलेशन में एक बग है?
val path = s"""c:\foo\bar\$fileName.csv"""
और बहु स्ट्रिंग शाब्दिक बिना एक अपवाद
java.lang.StringIndexOutOfBoundsException: String index out of range: 11
मिला ("""
) यह सिर्फ ठीक काम करता है वैल पथ = रों "" "c: \ foo \ बार \ $ fileName .csv "" " वैल पथ = एस" सी: \ foo \ bar \ $ {fileName} .csv "//> पथ: स्ट्रिंग = सी: \ foo \ bar \ myFile.csv
पुन: पेश करने के लिए और परीक्षण मुद्दा:
object wcScala10 {
util.Properties.versionString //> res0: String = version 2.10.0-RC1
val name = "James" //> name : String = James
val test1 = s"Hello $name" //> test1 : String = Hello James
val test2 = s"""Hello $name""" //> test2 : String = Hello James
val test3 = """Hello \$name""" //> test3 : String = Hello \$name
val test4 = s"""Hello \$name""" //> java.lang.StringIndexOutOfBoundsException:
//> String index out of range: 7
}
क्या यह अपवाद किसी बग के कारण है? या क्या स्ट्रिंग इंटरपोलेशन करते समय मुझे $ साइन से पहले बैकस्लैश का उपयोग करने की अनुमति नहीं है?
यहाँ स्टैकट्रेस की अधिक है:
java.lang.StringIndexOutOfBoundsException: String index out of range: 7
at java.lang.String.charAt(String.java:686)
at scala.collection.immutable.StringOps$.apply$extension(StringOps.scala :39)
at scala.StringContext$.treatEscapes(StringContext.scala:202)
at scala.StringContext$$anonfun$s$1.apply(StringContext.scala:90)
at scala.StringContext$$anonfun$s$1.apply(StringContext.scala:90)
at scala.StringContext.standardInterpolator(StringContext.scala:120)
at scala.StringContext.s(StringContext.scala:90)
at wcScala10$$anonfun$main$1.apply$mcV$sp(wcScala10.scala:9)
at org.scalaide.worksheet.runtime.library.WorksheetSupport$$anonfun$$exe
cute$1.apply$mcV$sp(WorksheetSupport.scala:76)
at org.scalaide.worksheet.runtime.library.WorksheetSupport$.redirected(W
orksheetSupport.scala:65)
at org.scalaide.worksheet.runtime.library.WorksheetSupport$.$execute(Wor
ksheetSupport.scala:75)
at wcScala10$.main(wcScal
Output exceeds cutoff limit.
अद्यतन:
अब के रूप में चिह्नित स्काला 2.10.1-RC1
https://issues.scala-lang.org/browse/SI-6631
के लिए तय वैसे , ठीक होने के बाद भी, इंटरपोलेशन करने और बचने से बचने का सही तरीकाका उपयोग कर रहा है:
val path = raw"c:\foo\bar\$fileName.csv"
उदा।
val fileName = "myFileName" //> fileName : String = myFileName
val path = raw"c:\foo\bar\$fileName.csv" //> path : String = c:\foo\bar\myFileName.csv
पी.एस. मुझे पता है कि यह एक आरसी है, और बग की संभावना है, बस यह सुनिश्चित नहीं है कि यह –
है, तो आप इसे https://issues.scala-lang.org पर डाल दें। देखो जब मैं एक "\" 'स्कैला> एस "" सी: \ foo \ bar $ fileName.csv "" res9: स्ट्रिंग = सी: ♀oo? ArX.csv' –
वाह हटाएं। अच्छा एक :) मैंने वहां पंजीकरण करने की कोशिश की, मुझे एक संदेश मिला जिसमें मुझे कोई अनुमति नहीं है, क्या आप जानते हैं कि मुझे क्या याद आ रही है? –