日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Scala程序将多行字符串转换为数组

發布時間:2023/12/1 编程问答 49 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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 language

Explanation:

說明:

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程序将多行字符串转换为数组的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。