vb System.String.Substring类(方法)实例源码

下面列出了vb System.String.Substring 类(方法)源码代码实例,从而了解它的用法。

作者:VB.NET开发    项目:Syste   
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

作者:VB.NET开发    项目:Syste   
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

作者:VB.NET开发    项目:Syste   
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

作者:VB.NET开发    项目:Syste   
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

作者:VB.NET开发    项目:Syste   
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

作者:VB.NET开发    项目:Syste   
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

作者:VB程序    项目:Syste   
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


问题


面经


文章

微信
公众号

扫码关注公众号