String类的方法 String类有许多方法可以帮助你处理字符串对象。 下表提供了一些最常用的方法:


You
You 2024-01-02 22:38:18 53580
分类专栏: 资讯

String类的方法

String类有许多方法可以帮助你处理字符串对象。 下表提供了一些最常用的方法:

SN 方法名称和说明
1

Public Shared Function Compare ( strA As String, strB As String ) As Integer
公共共享函数比较(strA As String,strB As String)As Integer

比较两个指定的字符串对象,并返回一个整数,指示它们在排序顺序中的相对位置。

2

Public Shared Function Compare ( strA As String, strB As String, ignoreCase As Boolean ) As Integer
公共共享函数比较(strA As String,strB As String,ignoreCase As Boolean)As Integer

比较两个指定的字符串对象,并返回一个整数,指示它们在排序顺序中的相对位置。 但是,如果布尔参数为true,它将忽略大小写。

3

Public Shared Function Concat ( str0 As String, str1 As String ) As String
公共共享函数Concat(str0 As String,str1 As String)As String

连接两个字符串对象。

4

Public Shared Function Concat ( str0 As String, str1 As String, str2 As String ) As String
公共共享函数Concat(str0 As String,str1 As String,str2 As String)As String

连接三个字符串对象。

5

Public Shared Function Concat ( str0 As String, str1 As String, str2 As String, str3 As String ) As String公共共享函数Concat(str0 As String,str1 As String,str2 As String,str3 As String)As String

连接四个字符串对象。

6

Public Function Contains ( value As String ) As Boolean
公共函数包含(值作为字符串)As Boolean

返回一个值,指示指定的字符串对象是否出现在此字符串中。

7

Public Shared Function Copy ( str As String ) As String
公共共享函数复制(str作为字符串)As String

创建与指定字符串具有相同值的新String对象。

8

pPublic Sub CopyTo ( sourceIndex As Integer, destination As Char(), destinationIndex As Integer, count As Integer )

将指定数量的字符从字符串对象的指定位置复制到Unicode字符数组中的指定位置。

9

Public Function EndsWith ( value As String ) As Boolean
公共函数endsWith(值作为字符串)As Boolean

确定字符串对象的结尾是否与指定的字符串匹配。

10

Public Function Equals ( value As String ) As Boolean
公共函数等于(值作为字符串)As Boolean

确定当前字符串对象,并指定字符串对象是否具有相同的值。

11

Public Shared Function Equals ( a As String, b As String ) As Boolean
公共共享函数等于(A作为字符串,B作为字符串)As Boolean

确定两个指定字符串对象是否具有相同的值。

12

Public Shared Function Format ( format As String, arg0 As Object ) As String
公共共享函数格式(格式作为字符串,arg0作为对象)As String

将指定字符串中的一个或多个格式项替换为指定对象的字符串表示形式。

13

Public Function IndexOf ( value As Char ) As Integer
公共函数IndexOf(价值为CHAR)As Integer

返回当前字符串中指定Unicode字符第一次出现的从零开始的索引。

14

Public Function IndexOf ( value As String ) As Integer
公共函数IndexOf(值作为字符串)As Integer

返回此实例中指定字符串第一次出现的从零开始的索引。

15

Public Function IndexOf ( value As Char, startIndex As Integer ) As Integer
公共函数IndexOf(值为char,则startIndex作为整数) As Integer

返回此字符串中指定Unicode字符第一次出现的从零开始的索引,从指定的字符位置开始搜索。

16

Public Function IndexOf ( value As String, startIndex As Integer ) As Integer
公共函数IndexOf(值作为字符串,则startIndex作为整数)As Integer

返回此实例中指定字符串第一次出现的从零开始的索引,开始在指定的字符位置搜索。

17

Public Function IndexOfAny ( anyOf As Char() ) As Integer
公共函数IndexOfAny(anyOf为CHAR())As Integer

返回在指定的Unicode字符数组中的任何字符的此实例中第一次出现的从零开始的索引。

18

Public Function IndexOfAny ( anyOf As Char(), startIndex As Integer ) As Integer
公共函数IndexOfAny(anyOf为char(),则startIndex作为整数)As Integer

返回在指定的Unicode字符数组中的任意字符的此实例中第一次出现的从零开始的索引,开始在指定的字符位置搜索。

19

Public Function Insert ( startIndex As Integer, value As String ) As String
公共函数Insert(的startIndex为整数,值作为字符串)As String

返回一个新字符串,其中指定的字符串插入到当前字符串对象中指定的索引位置。

20

Public Shared Function IsNullOrEmpty ( value As String ) As Boolean
公共共享函数IsNullOrEmpty(值作为字符串) As Boolean

指示指定的字符串是空还是空字符串。

21

Public Shared Function Join ( separator As String, ParamArray value As String() ) As String
公共共享函数加入(分隔符作为字符串,值的ParamArray作为字符串())As String

连接字符串数组的所有元素,使用每个元素之间指定的分隔符。

22

Public Shared Function Join ( separator As String, value As String(), startIndex As Integer, count As Integer ) As String
公共共享函数加入(分隔符作为字符串,值作为字符串(),则startIndex整数,算作整数)As String

使用每个元素之间指定的分隔符连接字符串数组的指定元素。

23

Public Function LastIndexOf ( value As Char ) As Integer
公共函数LastIndexOf(价值为CHAR) As Integer

返回当前字符串对象中指定Unicode字符的最后一次出现的从零开始的索引位置。

24

Public Function LastIndexOf ( value As String ) As Integer
公共函数LastIndexOf(值作为字符串) As Integer

返回当前字符串对象中指定字符串的最后一次出现的从零开始的索引位置。

25

Public Function Remove ( startIndex As Integer )As String
字符串作为公共函数删除 (startIndex 作为整数)As String

删除当前实例中的所有字符,从指定位置开始,并继续到最后一个位置,并返回字符串。

26

Public Function Remove ( startIndex As Integer, count As Integer ) As String
字符串作为公共函数删除 (startIndex 作为整数作为整数计数)As String

从指定位置开始删除当前字符串中指定数量的字符,并返回字符串。

27

Public Function Replace ( oldChar As Char, newChar As Char ) As String
公共函数替换(oldChar为char,newChar为CHAR)As String

用指定的Unicode字符替换当前字符串对象中指定Unicode字符的所有出现,并返回新字符串。

28

Public Function Replace ( oldValue As String, newValue As String ) As String
公共功能替换(属性oldValue作为字符串,newValue作为字符串)As String

将当前字符串对象中指定字符串的所有出现替换为指定的字符串,并返回新字符串。

29

Public Function Split ( ParamArray separator As Char() ) As String()
公共函数拆分(ParamArray分隔符作为Char())As String()

返回一个字符串数组,其中包含当前字符串对象中的子字符串,由指定的Unicode字符数组的元素分隔。

30

Public Function Split ( separator As Char(), count As Integer ) As String()
公共函数分割(分隔符为char(),计数为整数)As String()

返回一个字符串数组,其中包含当前字符串对象中的子字符串,由指定的Unicode字符数组的元素分隔。 int参数指定要返回的子字符串的最大数目。

31

Public Function StartsWith ( value As String ) As Boolean
公共函数StartsWith(值作为字符串)As Boolean

确定此字符串实例的开头是否与指定的字符串匹配。

32

Public Function ToCharArray As Char()
公共函数ToCharArray As CHAR()

返回包含当前字符串对象中所有字符的Unicode字符数组。

33

Public Function ToCharArray ( startIndex As Integer, length As Integer ) As Char()
公共函数ToCharArray(startIndex为整数,length为整数) As Char()

返回一个Unicode字符数组,其中包含当前字符串对象中的所有字符,从指定的索引开始,直到指定的长度。

34

Public Function ToLower As String
公共函数ToLower As String

返回此字符串的转换为小写的副本。

35

Public Function ToUpper As String
公共函数ToUpper As String

返回此字符串的转换为大写的副本。

36

Public Function Trim As String
公共函数Trim As String

从当前String对象中删除所有前导和尾部空格字符。

上面列出的方法并不详尽,请访问MSDN库获取完整的方法列表和String类构造函数。

例子:

下面的例子说明了上述一些方法:

比较字符串:

Module strings
   Sub Main()
      Dim str1, str2 As String
      str1 = "This is test"
      str2 = "This is text"
      If (String.Compare(str1, str2) = 0) Then
          Console.WriteLine(str1 + " and " + str2 +
                            " are equal.")
      Else
          Console.WriteLine(str1 + " and " + str2 +
                            " are not equal.")
      End If
      Console.ReadLine()
   End Sub
End Module

当上述代码被编译和执行时,它产生了以下结果:

This is test and This is text are not equal.

字符串包含字符串:

Module strings
   Sub Main()
      Dim str1 As String
      str1 = "This is test"
      If (str1.Contains("test")) Then
          Console.WriteLine("The sequence 'test' was found.")
      End If
      Console.ReadLine()
   End Sub
End Module

当上述代码被编译和执行时,它产生了以下结果:

The sequence 'test' was found.

获取的子字符串:

Module strings
   Sub Main()
      Dim str As String
      str = "Last night I dreamt of San Pedro"
      Console.WriteLine(str)
      Dim substr As String = str.Substring(23)
      Console.WriteLine(substr)
      Console.ReadLine()
   End Sub
End Module

当上述代码被编译和执行时,它产生了以下结果:

Last night I dreamt of San Pedro
San Pedro.

加入字符串:

Module strings
   Sub Main()
      Dim strarray As String() = {"Down the way where the nights are gay",
                          "And the sun shines daily on the mountain top",
                           "I took a trip on a sailing ship",
                          "And when I reached Jamaica",
                          "I made a stop"}
      Dim str As String = String.Join(vbCrLf, strarray)
      Console.WriteLine(str)
      Console.ReadLine()
   End Sub
End Module

当上述代码被编译和执行时,它产生了以下结果:

Down the way where the nights are gay
And the sun shines daily on the mountain top
I took a trip on a sailing ship
And when I reached Jamaica
I made a stop

 

 
 
以上内容是否对您有帮助:

网站声明:如果转载,请联系本站管理员。否则一切后果自行承担。

本文链接:https://www.xckfsq.com/news/show.html?id=34396
赞同 0
评论 0 条
YouL0
粉丝 0 发表 582 + 关注 私信
上周热门
如何使用 StarRocks 管理和优化数据湖中的数据?  2951
【软件正版化】软件正版化工作要点  2872
统信UOS试玩黑神话:悟空  2833
信刻光盘安全隔离与信息交换系统  2728
镜舟科技与中启乘数科技达成战略合作,共筑数据服务新生态  1261
grub引导程序无法找到指定设备和分区  1226
华为全联接大会2024丨软通动力分论坛精彩议程抢先看!  165
2024海洋能源产业融合发展论坛暨博览会同期活动-海洋能源与数字化智能化论坛成功举办  163
点击报名 | 京东2025校招进校行程预告  163
华为纯血鸿蒙正式版9月底见!但Mate 70的内情还得接着挖...  159
本周热议
我的信创开放社区兼职赚钱历程 40
今天你签到了吗? 27
如何玩转信创开放社区—从小白进阶到专家 15
信创开放社区邀请他人注册的具体步骤如下 15
方德桌面操作系统 14
用抖音玩法闯信创开放社区——用平台宣传企业产品服务 13
我有15积分有什么用? 13
如何让你先人一步获得悬赏问题信息?(创作者必看) 12
2024中国信创产业发展大会暨中国信息科技创新与应用博览会 9
中央国家机关政府采购中心:应当将CPU、操作系统符合安全可靠测评要求纳入采购需求 8

加入交流群

请使用微信扫一扫!