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关键字创建范围的简单方法。

Syntax:

句法:

    startchar to endchar

程序创建一系列字符 (Program to create a range of characters)

object myObject {    
    def main(args: Array[String]) {
        val string = ('i' to 'z').toArray
        for(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 z 

You can also choose the value to be incremented, i.e. you can skip any number of elements while creating this range.

您也可以选择要增加的值,即在创建此范围时可以跳过任何数量的元素。

程序以间隔创建范围 (Program to create a range with interval)

object myObject {    
    def main(args: Array[String]) {
        val string = ('A' to 'K' by 3).toArray
        for(i <- 0 to string.length-1)
        print(string(i) + " ")
    }
}

Output

输出量

A D G J 

This 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等。

创建ASCII范围 (Create ASCII Range)

You can also create a range of ASCII of the value of character within the given range.

您还可以在给定范围内创建字符值的ASCII范围。

Syntax:

句法:

    array.range('startChar' , 'endChar')

程序以创建一系列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中字符串计数

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值