scala字符串的拉链操作_在Scala中对字符串进行操作

scala字符串的拉链操作

Scala字符串操作 (Scala strings operation)

A string is a very important datatype in Scala. This is why there are a lot of operations that can be done on the string object. Since the regular operations like addition, subtraction is not valid for a string, therefore, special operations like concatenation, comparison are defined.

字符串是Scala中非常重要的数据类型。 这就是为什么可以对字符串对象执行许多操作的原因。 由于常规操作(如加法,减法)对于字符串无效,因此,定义了特殊操作(如串联,比较)。

In this tutorial, we will share some of the important and common string functions.

在本教程中,我们将分享一些重要和通用的字符串函数

1)字符串相等(==) (1) String Equality (==))

The tradition equality operator == is also available in the string. You can use it to find equality of two string and the equality results in a boolean value.

字符串中也可以使用传统的等于运算符== 。 您可以使用它来查找两个字符串的相等性,并且相等性会产生布尔值。

    str1 = str2 // this will return either TRUE OR FALSE 

For Example,

例如,

    val str1 = "Include"
val str2 = "Includes"
str1 == str2 // this will be false

2)字符串长度 (2) String Length)

There is an inbuilt function that is used to find the number of characters in a string. It includes all the space that comes it between. It is used to set the limit for string traversal.

有一个内置函数,用于查找字符串中的字符数。 它包括介于两者之间的所有空间。 用于设置字符串遍历的限制。

    // this outputs a positive integer denoting the // number of characters in the array. str1.length 

For example,

例如,

    val str1 = "Include help"
str1.length // this will print 12

3)串连音 (3) String concat)

You can concatenate a string on other. It means the string will be appended on the calling string.

您可以在其他字符串上串联一个字符串。 这意味着该字符串将附加在调用字符串上。

    str1.concat(str2)

for example,

例如,

    val str1 = "Include"
val str2 = "Help"
str1.concat(str2) // This will print IncludeHelp

4)字符串charAt()方法 (4) String charAt() method )

To print the character at a specific index of the string the charAt method is used. The input is a zero-based index and output will be the corresponding character. Will throw an error if the input is greater than the length of the string.

要在字符串的特定索引处打印字符,请使用charAt方法。 输入是从零开始的索引,输出将是相应的字符。 如果输入大于字符串的长度,将引发错误。

    str1.charAt(n)

For example,

例如,

    val name = "Include"
name.charAt(4) // This will output u.

5)indexOf()方法 (5) indexOf() method)

The indexOf() method is used to check the index of a character in a string. This method returns an integer which is positive within the length of the string when the character is found in the array otherwise -1 is given as output.

indexOf()方法用于检查字符串中字符的索引。 当在数组中找到字符时,此方法返回一个整数,该整数在字符串的长度内为正,否则将给出-1作为输出。

    str1.indexOf("a")

For example,

例如,

    val name = "Include"
name.indexOf("d") // This will output 5.

6)Substring()方法 (6) Substring() method)

The substring method is used to define a substring from the calling string. It makes a new string with the specified part of the string.

substring方法用于从调用字符串中定义一个子字符串。 它使用字符串的指定部分创建一个新字符串。

    str2 =  str1.substring(startIndex , endIndex)

For example,

例如,

    val name = "IncludeHelp is awesome"
name.substring(14 , 21) // This will output awesome.

Example code that uses all these functions

使用所有这些功能的示例代码

object MyClass {
def main(args: Array[String]) {
val str1 = "include Help "
val str2 = "is awesome"
println("str1 = " + str1)
println("str2 = " + str2)
println("Comparison between str1 and str2 is " + (str1 == str2))
println("The length of str1 is " + str1.length)
println("Concatenating str1 with str2 gives \n " + str1.concat(str2))
println("The character at  index 5 of str2 is" + str2.charAt(5))
println("The index of 'c' in str1 is " + str1.indexOf("c"))
}
}

Output

输出量

str1 = include Help 
str2 = is awesome
Comparison between str1 and str2 is false
The length of str1 is 13
Concatenating str1 with str2 gives include Help is awesome
The character at  index 5 of str2 ise
The index of 'c' in str1 is 2

翻译自: https://www.includehelp.com/scala/operation-on-strings-in-scala.aspx

scala字符串的拉链操作

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/377573.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

九、池化层

一、Pooling layers Pooling layers官网文档 MaxPool最大池化层下采样 MaxUnpool最大池化层上采样 AvgPool最大池化层平均采样 例如:池化核为(3,3),输入图像为(5,5),步长为1,不加边 最大池化就是选出在池化核为单位图像中的最大…

[分享]SharePoint移动设备解决方案

老外写的一个PPT,讲SharePoint在移动领域的应用,2012年最新的,有iPad哟。/Files/zhaojunqi/SharePoint2010andMobileDevices.pdf 转载于:https://www.cnblogs.com/zhaojunqi/archive/2012/04/12/2444712.html

十、非线性激活函数

一、ReLU torch.nn.ReLU(inplaceFalse)官网提供的API 其中inplace表示是否在对原始数据进行替换 由函数图可以看出,负数通过ReLU之后会变成0,正数则不发生变化 例如:input -1,若inplace True,表示对原始输入数据进…

最短公共子序列_最短公共超序列

最短公共子序列Problem statement: 问题陈述: Given two strings, you have to find the shortest common super sequence between them and print the length of the super sequence. 给定两个字符串,您必须找到它们之间最短的公共超级序列&#xff0c…

单调栈 leetcode整理(二)

目录为什么单调栈的时间复杂度是O(n)496. 下一个更大元素 I方法一:暴力方法二:单调栈哈希表739. 每日温度单调栈模版解优化503. 下一个更大元素 II单调栈循环遍历为什么单调栈的时间复杂度是O(n) 尽管for 循环里面还有while 循环,但是里面的while最多执…

Android中引入第三方Jar包的方法(java.lang.NoClassDefFoundError解决办法)

ZZ:http://www.blogjava.net/anchor110/articles/355699.html1、在工程下新建lib文件夹,将需要的第三方包拷贝进来。2、将引用的第三方包,添加进工作的build path。3、(关键的一步)将lib设为源文件夹。如果不设置&…

QTP自传之web常用对象

随着科技的进步,“下载-安装-运行”这经典的三步曲已离我们远去。web应用的高速发展,改变了我们的思维和生活习惯,同时也使web方面的自动化测试越来越重要。今天,介绍一下我对web对象的识别,为以后的对象库编程打下基础…

leetcode中使用c++需要注意的点以及各类容器的初始化、常用成员函数

目录1、传引用2、vector使用初始化方法常用成员函数3、字符串string初始化方法常用成员函数4、哈希表 unordered_map初始化常用成员函数示例:计数器5、哈希集合 unordered_set初始化常用成员函数6、队列 queue初始化成员函数7、栈stack初始化常用成员函数7、emplace…

Linq list 排序,Dictionary 排序

C# 对List成员排序的简单方法 http://blog.csdn.net/wanzhuan2010/article/details/6205884 LINQ之路系列博客导航 http://www.cnblogs.com/lifepoem/archive/2011/12/16/2288017.html 用一句Linq把一个集合的属性值根据条件改了,其他值不变 list去重 list.Where((x…

javascript Ajax 同步请求与异步请求的问题

先来看以下代码: var flagtrue; var index0; $.ajax({url: "http://www.baidu.com/",success: function(data){flagfalse;} }); while(flag){index; } alert(index); 请问最后alert的index的结果是多少? 可能有人会说0呗。实际上却没那么简单…

定义类的Python示例

The task to define a class in Python. 在Python中定义类的任务。 Here, we are defining a class named Number with an attribute num, initializing it with a value 123, then creating two objects N1 and N2 and finally, printing the objects memory locations and a…

十一、线性层

一、Linear Layers torch.nn.Linear(in_features, out_features, biasTrue, deviceNone, dtypeNone) 以VGG神经网络为例,Linear Layers可以将特征图的大小进行变换由(1,1,4096)转换为(1,1,1000) 二、torch.nn.Linear实战 将CIFAR-10数据集中的测试集二维图像[6…

easyui plugin——etreegrid:CRUD Treegrid

昨天写了一个koeasyui的同样的实现,感觉写的太乱,用起来十分麻烦,于是今天照着edatagrid,写了一个etreegrid,这样再用ko绑定就方便多了。 使用很简单,$(tableId).etreegrid({idField:parentIdField:,treeField:,saveUr…

expr

expr在linux中 是一个功能非常强大的命令。通过学习做一个小小的总结。 1、计算字符串的长度。我们可以用awk中的length(s)进行计算。我们 也可以用echo中的echo ${#string}进行计算,当然也可以expr中的expr length $string 求出字符串的长度。举 例[rootlocalhost …

leetcode 42. 接雨水 思考分析(暴力、动态规划、双指针、单调栈)

目录题目思路暴力法动态规划双指针法单调栈题目 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子,下雨之后能接多少雨水。 输入:height [0,1,0,2,1,0,1,3,2,1,2,1] 输出:6 解释:上面是由数组…

chdir函数_PHP chdir()函数与示例

chdir函数PHP chdir()函数 (PHP chdir() function) The full form of chdir is "Change Directory", the function chdir() is used to change the current working directory. chdir的完整形式是“更改目录” , 功能chdir()用于更改当前工作目录。 Synt…

十二、Sequential

一、Sequential介绍 torch.nn.Sequential(*args) 由官网给的Example可以大概了解到Sequential是将多层网络进行便捷整合,方便可视化以及简化网络复杂性 二、复现网络模型训练CIFAR-10数据集 这里面有个Hidden units隐藏单元其实就是连个线性层 把隐藏层全部展开整…

1064-快速排序

描述 给定输入排序元素数目n和相应的n个元素,写出程序,利用内排序算法中快速排序算法进行排序,并输出排序最后结果的相应序列。 输入 共两行,第一行给出排序元素数目n,第二行给出n个元素,1≤n≤100000&…

社交问答:取代BBS的Web2.0革命

编者按:本文由乐维UP创始人俞越撰写,你也可以点击这里关注俞越的新浪微博。 BBS在中国的兴起是在95年,之后以惊人的速度发展起来。从2011年开始,国内的问答社区也如当年的BBS一样,大量涌现快速成长,大体分为…

单调栈 leetcode整理(三)

目录42. 接雨水思路分析901. 股票价格跨度思路581. 最短无序连续子数组思路一:排序双指针思路二:单调栈思路三:双指针(最省时)42. 接雨水 42. 接雨水 给定 n 个非负整数表示每个宽度为 1 的柱子的高度图,计算按此排列的柱子&…