12、string.GetHashCode获取哈希值
获取对应的哈希值,返回结果为Integer类型,例如:
TestString = "string"
/// 结果
TestString.GetHashCode = 1236128813
13、string.IndexOf获取索引值
获取指定内容在字符串中的索引值,索引从0开始,或没有则返回-1,返回结果为Integer类型,例如:
//例1: 判断单独一个字母或字符时,返回对应的索引值
StringA = "string123456"
/// 结果
StringA.IndexOf("t") = 1
//例2: 判断多个字母或字符时,返回第一个对应的索引值
StringA = "string123456"
/// 结果
StringA.IndexOf("tring") = 1
//例3: 未找到,则返回值为-1
StringA = "string123456"
/// 结果
StringA.IndexOf("strr") = -1
14、string.IndexOfAny获取任意索引值
获取任意一个字符的索引,索引从0开始,或没有则返回-1,这里需要添加的是字符组,例如:
//例1:字符串会从字符数组中一个一个的循环搜索,如先在字符串中搜索a字符的索引值, 若没有找到则查询字符b,直到查询到字符1时,返回的索引值为6,则结束,返回结果为6,数组后面的字符将不再匹配查询
TestString = "string123456"
char[] TestCharArray = "abc123".ToCharArray
/// 结果
TestString.IndexOfAny(TestCharArray) = 6
15、string.Insert插入字符串
在某一字符串中指定索引位置插入指定内容,索引值从0开始,返回类型为String,例如:
//例1:在索引值为6处插入字符串“Test”
TestString = "string123456"
/// 结果
TestString.Insert(6,"Test") = "stringTest123456"
16、string.Join连接字符串
使用指定连接符,使其多个字符串连接起来,例如:
//例1:将三个字符串通过“-”连接符连接起来
TestStringA = "string"
TestStringB = "123"
TestStringC = "456"
/// 结果
//注意:这里的join是可以连接多个字符串,所以引用join方法是使用string.join即可,如果使用某一个指定的字符串引用其效果一样,并不是在引用的字符串后面连接其他字符串
String.Join("-", TestStringA, TestStringB, TestStringC) = "string-123-456"
TestStringA.Join("-", TestStringA, TestStringB, TestStringC) = "string-123-456"
17、string.Last查询末尾字符
这里与之前的first查询相反,查询的是末尾最后一个字符内容,例如:
TestString = "string"
/// 结果
TestString.Last = "g"
18、string.LastIndexOf获取索引值
获取指定内容在字符串中的索引值(最后一个索引),索引从0开始,或没有则返回-1,返回结果为Integer类型,例如:
//例1:搜索1在字符串中的索引值
TestString = "string123456"
/// 结果
TestString.LastIndexOf("1") = 6
//例2:区分LastIndexOf和IndexOf
//LastIndexOf是最后一次出现的索引值,IndexOf是第一次出现的索引值。如下:
TestString = "string1234516"
/// 结果
TestString.LastIndexOf("1") = 11
TestString.IndexOf("1") = 6
19、string.LastIndexOfAny获取任意索引值
获取任意一个字符的索引,索引从0开始,或没有则返回-1,这里需要添加的是字符组,只不过这里与indexof相比是获取的字符串最后一次出现的索引值,具体例子与string.IndexOfAny的类似,这里就不列举了。
20、string.Length获取长度
获取字符串长度,返回结果为Integer类型,例如:
TestString = "string123456"
/// 结果
TestString.Length = 12
21、string.LongCount获取长度
与length没什么区别,都可以计算字符串的长度,只不过返回结果为Long类型:
TestString = "string123456"
/// 结果
TestString.LongCount = 12
22、string.Max获取最大字符
这里最大是通过比较字符对应的ASCII编码,从而返回编码最大的字符,例如:
TestString = "string123456"
/// 结果
TestString.Max = "t"
23、string.Min获取最小字符
这里最小是通过比较字符对应的ASCII编码,从而返回编码最小的字符,例如:
TestString = "string123456"
/// 结果
TestString.Min = "1"
关于字符串处理还有一下链接:
uipath 字符串处理常用.net方法(一):https://blog.csdn.net/hotkoko/article/details/123631505
uipath 字符串处理常用.net方法(二):https://blog.csdn.net/hotkoko/article/details/123666764