• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

VB.NET String.StartsWith方法代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.String.StartsWith方法的典型用法代码示例。如果您正苦于以下问题:VB.NET String.StartsWith方法的具体用法?VB.NET String.StartsWith怎么用?VB.NET String.StartsWith使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.String的用法示例。



在下文中一共展示了String.StartsWith方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: Example

Public Class Example
   Public Shared Sub Main()
      Dim strSource() As String = { "<b>This is bold text</b>", 
                         "<H1>This is large Text</H1>", 
                         "<b><i><font color = green>This has multiple tags</font></i></b>", 
                         "<b>This has <i>embedded</i> tags.</b>", 
                         "<This line simply begins with a lesser than symbol, it should not be modified" }

      ' Display the initial string array.
      Console.WriteLine("The original strings:")
      Console.WriteLine("---------------------")
      For Each s In strSource
         Console.WriteLine(s)
      Next 
      Console.WriteLine()

      Console.WriteLine("Strings after starting tags have been stripped:")
      Console.WriteLine("-----------------------------------------------") 

      ' Display the strings with starting tags removed.
      For Each s In strSource
         Console.WriteLine(StripStartTags(s))
      Next 
   End Sub 

   Private Shared Function StripStartTags(item As String) As String
      ' Determine whether a tag begins the string.
      If item.Trim().StartsWith("<") Then
         ' Find the closing tag.
         Dim lastLocation As Integer = item.IndexOf(">")
         If lastLocation >= 0 Then
            ' Remove the tag.
            item = item.Substring((lastLocation + 1))
            
            ' Remove any additional starting tags.
            item = StripStartTags(item)
         End If
      End If
      
      Return item
   End Function 
End Class
开发者ID:VB.NET开发者,项目名称:System,代码行数:42,代码来源:String.StartsWith

输出:

The original strings:
---------------------
This is bold text

This is large Text

This has multiple tags This has embedded tags. This is large Text This has multiple tags This has embedded tags.


示例2: Example

Module Example
   Public Sub Main()
      Dim title As String = "The House of the Seven Gables"
      Dim searchString As String = "the"
      Dim comparison As StringComparison = StringComparison.InvariantCulture
      Console.WriteLine("'{0}':", title)
      Console.WriteLine("   Starts with '{0}' ({1:G} comparison): {2}",
                        searchString, comparison,
                        title.StartsWith(searchString, comparison))

      comparison = StringComparison.InvariantCultureIgnoreCase
      Console.WriteLine("   Starts with '{0}' ({1:G} comparison): {2}",
                        searchString, comparison,
                        title.StartsWith(searchString, comparison))
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:16,代码来源:String.StartsWith

输出:

The House of the Seven Gables':
Starts with 'the' (InvariantCulture comparison): False
Starts with 'the' (InvariantCultureIgnoreCase comparison): True


示例3: Example

Module Example
   Public Sub Main()
      Dim strings(,) As String = { {"ABCdef", "abc" },                    
                                   {"ABCdef", "abc" },  
                                   {"œil","oe" },
                                   { "læring}", "lae" } }
      For ctr1 As Integer = strings.GetLowerBound(0) To strings.GetUpperBound(0)
            For Each cmpName As String In [Enum].GetNames(GetType(StringComparison)) 
               Dim strCmp As StringComparison = CType([Enum].Parse(GetType(StringComparison), 
                                                      cmpName), StringComparison)
               Dim instance As String = strings(ctr1, 0)
               Dim value As String = strings(ctr1, 1)
               Console.WriteLine("{0} starts with {1}: {2} ({3} comparison)", 
                                 instance, value, 
                                 instance.StartsWith(value, strCmp), 
                                 strCmp) 
            Next
            Console.WriteLine()   
      Next   
   End Sub
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:21,代码来源:String.StartsWith

输出:

ABCdef starts with abc: False (CurrentCulture comparison)
ABCdef starts with abc: True (CurrentCultureIgnoreCase comparison)
ABCdef starts with abc: False (InvariantCulture comparison)
ABCdef starts with abc: True (InvariantCultureIgnoreCase comparison)
ABCdef starts with abc: False (Ordinal comparison)
ABCdef starts with abc: True (OrdinalIgnoreCase comparison)

ABCdef starts with abc: False (CurrentCulture comparison)
ABCdef starts with abc: True (CurrentCultureIgnoreCase comparison)
ABCdef starts with abc: False (InvariantCulture comparison)
ABCdef starts with abc: True (InvariantCultureIgnoreCase comparison)
ABCdef starts with abc: False (Ordinal comparison)
ABCdef starts with abc: True (OrdinalIgnoreCase comparison)

œil starts with oe: True (CurrentCulture comparison)
œil starts with oe: True (CurrentCultureIgnoreCase comparison)
œil starts with oe: True (InvariantCulture comparison)
œil starts with oe: True (InvariantCultureIgnoreCase comparison)
œil starts with oe: False (Ordinal comparison)
œil starts with oe: False (OrdinalIgnoreCase comparison)

læring} starts with lae: True (CurrentCulture comparison)
læring} starts with lae: True (CurrentCultureIgnoreCase comparison)
læring} starts with lae: True (InvariantCulture comparison)
læring} starts with lae: True (InvariantCultureIgnoreCase comparison)
læring} starts with lae: False (Ordinal comparison)
læring} starts with lae: False (OrdinalIgnoreCase comparison)


示例4: Sample

' This code example demonstrates the 
' System.String.StartsWith(String, ..., CultureInfo) method.

Imports System.Threading
Imports System.Globalization

Class Sample
    Public Shared Sub Main() 
        Dim msg1 As String = "Search for the target string ""{0}"" in the string ""{1}""." & vbCrLf
        Dim msg2 As String = "Using the {0} - ""{1}"" culture:"
        Dim msg3 As String = "  The string to search ends with the target string: {0}"
        Dim result As Boolean = False
        Dim ci As CultureInfo
        
        ' Define a target string to search for.
        ' U+00c5 = LATIN CAPITAL LETTER A WITH RING ABOVE
        Dim capitalARing As String = "Å"
        
        ' Define a string to search. 
        ' The result of combining the characters LATIN SMALL LETTER A and COMBINING 
        ' RING ABOVE (U+0061, U+030a) is linguistically equivalent to the character 
        ' LATIN SMALL LETTER A WITH RING ABOVE (U+00e5).
        Dim aRingXYZ As String = "å" & "xyz"
        
        ' Clear the screen and display an introduction.
        Console.Clear()
        
        ' Display the string to search for and the string to search.
        Console.WriteLine(msg1, capitalARing, aRingXYZ)
        
        ' Search using English-United States culture.
        ci = New CultureInfo("en-US")
        Console.WriteLine(msg2, ci.DisplayName, ci.Name)
        
        Console.WriteLine("Case sensitive:")
        result = aRingXYZ.StartsWith(capitalARing, False, ci)
        Console.WriteLine(msg3, result)
        
        Console.WriteLine("Case insensitive:")
        result = aRingXYZ.StartsWith(capitalARing, True, ci)
        Console.WriteLine(msg3, result)
        Console.WriteLine()
        
        ' Search using Swedish-Sweden culture.
        ci = New CultureInfo("sv-SE")
        Console.WriteLine(msg2, ci.DisplayName, ci.Name)
        
        Console.WriteLine("Case sensitive:")
        result = aRingXYZ.StartsWith(capitalARing, False, ci)
        Console.WriteLine(msg3, result)
        
        Console.WriteLine("Case insensitive:")
        result = aRingXYZ.StartsWith(capitalARing, True, ci)
        Console.WriteLine(msg3, result)
    
    End Sub
End Class

'
'Note: This code example was executed on a console whose user interface 
'culture is "en-US" (English-United States).
'
'Search for the target string "Å" in the string "a°xyz".
'
'Using the English (United States) - "en-US" culture:
'Case sensitive:
'  The string to search ends with the target string: False
'Case insensitive:
'  The string to search ends with the target string: True
'
'Using the Swedish (Sweden) - "sv-SE" culture:
'Case sensitive:
'  The string to search ends with the target string: False
'Case insensitive:
'  The string to search ends with the target string: False
'
开发者ID:VB.NET开发者,项目名称:System,代码行数:76,代码来源:String.StartsWith


示例5: MainClass

' 导入命名空间
Imports System

Public Class MainClass

   Shared Sub Main()
      Dim strings As String()
      Dim i As Integer
      Dim quotes As Char = ChrW(34)

      strings = New String() {"started", "starting", _
         "ended", "ending"}

      Console.WriteLine(" test every string to see if it starts with 'st'")
      For i = 0 To strings.GetUpperBound(0)

         If strings(i).StartsWith("st") Then
            Console.WriteLine(quotes & strings(i) & quotes & _
               " starts with " & quotes & "st" & quotes )
         End If

      Next

      Console.WriteLine(" test every string to see if it ends with 'ed'")
      For i = 0 To strings.GetUpperBound(0)

         If strings(i).EndsWith("ed") Then
            Console.WriteLine( quotes & strings(i) & quotes & _
               " ends with " & quotes & "ed" & quotes )
         End If

      Next
   End Sub ' Main

End Class
开发者ID:VB程序员,项目名称:System,代码行数:35,代码来源:String.StartsWith



注:本文中的System.String.StartsWith方法示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET Timer.Stop方法代码示例发布时间:2022-05-24
下一篇:
VB.NET String.IsInterned方法代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap