Permalink
Browse files

String#length

export JAVA_OPTS='-Dfile.encoding=UTF-8'
  • Loading branch information...
1 parent f03cfd0 commit 2a77eedbd42d8da46b7e3c0fcd8aaf7b344473ae @rightgo09 committed Dec 30, 2012
Showing with 14 additions and 0 deletions.
  1. +12 −0 03-05/TextCounter040.scala
  2. +2 −0 03-05/data.txt
View
12 03-05/TextCounter040.scala
@@ -0,0 +1,12 @@
+import scala.io.Source
+
+val filename = args(0)
+val src = Source.fromFile(filename) // オブジェクトを取得
+var charCount = 0
+var lineCount = 0
+val lines = src.getLines
+for (line <- lines) {
+ charCount += line.length
+ lineCount += 1
+}
+println("文字数 = " + charCount + ", 行数 = " + lineCount)
View
2 03-05/data.txt
@@ -0,0 +1,2 @@
+Hello Wolrd
+Scala Programming Sample

0 comments on commit 2a77eed

Please sign in to comment.