Scala程序将多行字符串转换为数组
Scala | 多行字符串到數組 (Scala | Multiline strings to an array)
Scala programming language is employed in working with data logs and their manipulation. Data logs are entered into the code as a single string which might contain multiple lines of code and to work properly with this type of strings we need to convert multiline string to an array of single-line string in Scala.
Scala編程語言用于處理數據日志及其操作。 數據日志作為單個字符串輸入到代碼中,其中可能包含多行代碼,并且要與這種類型的字符串正常工作,我們需要在Scala中將多行字符串轉換為單行字符串數組 。
Here, is the program that will be helpful to you in converting a multiline string to an array.
這是在將多行字符串轉換為array時將對您有所幫助的程序。
object myObject { def main(args:Array[String]) { val data = """This is a multiline string in Scala programming language"""val dataArr = data.split("\n").filter(_ != "")println("Array conversion of the given multiline string is : ")for(i <- 0 to dataArr.length-1)println(dataArr(i))} }Output
輸出量
Array conversion of the given multiline string is : This is a multiline string in Scala programming languageExplanation:
說明:
To convert the given multiline string to an array. Here, we have used two methods: split and filter.
將給定的多行字符串轉換為數組 。 在這里,我們使用了兩種方法: split和filter 。
翻譯自: https://www.includehelp.com/scala/program-to-convert-multiline-strings-to-an-array.aspx
總結
以上是生活随笔為你收集整理的Scala程序将多行字符串转换为数组的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: “羽盖伫宣游”上一句是什么
- 下一篇: java uuid静态方法_Java U