scala中字符串计数_如何在Scala中创建一系列字符?
scala中字符串計數
The range is a set of data from a lower value to a larger value. In Scala, we have an easy method to create a range using to keyword.
范圍是從較低值到較大值的一組數據。 在Scala中,我們有一種使用to關鍵字創(chuàng)建范圍的簡單方法。
Syntax:
句法:
startchar to endchar程序創(chuàng)建一系列字符 (Program to create a range of characters)
object myObject { def main(args: Array[String]) {val string = ('i' to 'z').toArrayfor(i <- 0 to string.length-1)print(string(i) + " ")} }Output
輸出量
i j k l m n o p q r s t u v w x y zYou can also choose the value to be incremented, i.e. you can skip any number of elements while creating this range.
您也可以選擇要增加的值,即在創(chuàng)建此范圍時可以跳過任何數量的元素。
程序以間隔創(chuàng)建范圍 (Program to create a range with interval)
object myObject { def main(args: Array[String]) {val string = ('A' to 'K' by 3).toArrayfor(i <- 0 to string.length-1)print(string(i) + " ")} }Output
輸出量
A D G JThis range of characters is converted to the array here, we can convert the same to List, vectors, etc using toList and toVector methods respectively.
此范圍的字符在此處轉換為數組,我們可以分別使用toList和toVector方法將其轉換為List,vector等。
創(chuàng)建ASCII范圍 (Create ASCII Range)
You can also create a range of ASCII of the value of character within the given range.
您還可以在給定范圍內創(chuàng)建字符值的ASCII范圍。
Syntax:
句法:
array.range('startChar' , 'endChar')程序以創(chuàng)建一系列ASCII值 (Program to create a range of ASCII values)
object myObject { def main(args: Array[String]) {val ASCIIrange = Array.range('A', 'K')for(i <- 0 to ASCIIrange.length-1)print(ASCIIrange(i) + " ")} }Output
輸出量
65 66 67 68 69 70 71 72 73 74翻譯自: https://www.includehelp.com/scala/how-to-create-a-range-of-characters-in-scala.aspx
scala中字符串計數
總結
以上是生活随笔為你收集整理的scala中字符串计数_如何在Scala中创建一系列字符?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: _.uniq_在Ruby中使用Array
- 下一篇: java scanner_Java Sc