本文整理汇总了VB.NET中System.String.Substring方法的典型用法代码示例。如果您正苦于以下问题:VB.NET String.Substring方法的具体用法?VB.NET String.Substring怎么用?VB.NET String.Substring使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String 的用法示例。
在下文中一共展示了String.Substring方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。
示例1: SubStringTest
Public Class SubStringTest
Public Shared Sub Main()
Dim info As String() = { "Name: Felica Walker", "Title: Mz.",
"Age: 47", "Location: Paris", "Gender: F"}
Dim found As Integer = 0
Console.WriteLine("The initial values in the array are:")
For Each s As String In info
Console.WriteLine(s)
Next s
Console.WriteLine(vbCrLf + "We want to retrieve only the key information. That is:")
For Each s As String In info
found = s.IndexOf(": ")
Console.WriteLine(" {0}", s.Substring(found + 2))
Next s
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:18,代码来源:String.Substring 输出:
The initial values in the array are:
Name: Felica Walker
Title: Mz.
Age: 47
Location: Paris
Gender: F
We want to retrieve only the key information. That is:
Felica Walker
Mz.
47
Paris
F
示例2: Example
Module Example
Public Sub Main()
Dim pairs() As String = { "Color1=red", "Color2=green", "Color3=blue",
"Title=Code Repository" }
For Each pair In pairs
Dim position As Integer = pair.IndexOf("=")
If position < 0 then Continue For
Console.WriteLine("Key: {0}, Value: '{1}'",
pair.Substring(0, position),
pair.Substring(position + 1))
Next
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:13,代码来源:String.Substring 输出:
Key: Color1, Value: 'red'
Key: Color2, Value: 'green'
Key: Color3, Value: 'blue'
Key: Title, Value: 'Code Repository'
示例3: Example
Module Example
Public Sub Main()
Dim value As String = "This is a string."
Dim startIndex As Integer = 5
Dim length As Integer = 2
Dim substring As String = value.Substring(startIndex, length)
Console.WriteLine(substring)
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:9,代码来源:String.Substring 输出:
is
示例4: Sample
Public Class Sample
Public Shared Sub Main()
Dim myString As String = "abc"
Dim test1 As Boolean = myString.Substring(2, 1).Equals("c") ' This is true.
Console.WriteLine(test1)
Dim test2 As Boolean = String.IsNullOrEmpty(myString.Substring(3, 0)) ' This is true.
Console.WriteLine(test2)
Try
Dim str3 As String = myString.Substring(3, 1) ' This throws ArgumentOutOfRangeException.
Console.WriteLine(str3)
Catch e As ArgumentOutOfRangeException
Console.WriteLIne(e.Message)
End Try
End Sub
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:15,代码来源:String.Substring 输出:
True
True
Index and length must refer to a location within the string.
Parameter name: length
示例5: Example
Module Example
Public Sub Main()
Dim s As String = "aaaaabbbcccccccdd"
Dim charRange As Char = "b"c
Dim startIndex As Integer = s.Indexof(charRange)
Dim endIndex As Integer = s.LastIndexOf(charRange)
Dim length = endIndex - startIndex + 1
Console.WriteLine("{0}.Substring({1}, {2}) = {3}",
s, startIndex, length,
s.Substring(startIndex, length))
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:12,代码来源:String.Substring 输出:
aaaaabbbcccccccdd.Substring(5, 3) = bbb
示例6: Example
Module Example
Public Sub Main()
Dim s As String = "<term>extant<definition>still in existence</definition></term>"
Dim searchString As String = "<definition>"
Dim startindex As Integer = s.IndexOf(searchString)
searchString = "</" + searchString.Substring(1)
Dim endIndex As Integer = s.IndexOf(searchString)
Dim substring As String = s.Substring(startIndex, endIndex + searchString.Length - StartIndex)
Console.WriteLine("Original string: {0}", s)
Console.WriteLine("Substring; {0}", substring)
End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:12,代码来源:String.Substring 输出:
Original string: extantstill in existence
Substring; still in existence
示例7: String.Substring(Int begin)
Public Class MainClass
Public Shared Sub Main()
'Strings
Dim strConstant As String = "ABC"
Dim strRepeat As New String("A"c, 20)
Dim strMyString As String = "Hello World"
Console.WriteLine(strMyString.Substring(0, 5))
Console.WriteLine(strMyString.Substring(6))
End Sub
End Class
开发者ID:VB程序员,项目名称:System,代码行数:13,代码来源:String.Substring
注:本文中的System.String.Substring方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论