當前位置: 首頁>>代碼示例>>VB.NET>>正文


VB.NET String.Replace方法代碼示例

本文整理匯總了VB.NET中System.String.Replace方法的典型用法代碼示例。如果您正苦於以下問題:VB.NET String.Replace方法的具體用法?VB.NET String.Replace怎麽用?VB.NET String.Replace使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.String的用法示例。


在下文中一共展示了String.Replace方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。

示例1: Example

Module Example
   Public Sub Main()
      Dim s As String = "aaa"
      Console.WriteLine("The initial string: '{0}'", s)
      s = s.Replace("a", "b").Replace("b", "c").Replace("c", "d")
      Console.WriteLine("The final string: '{0}'", s)
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:8,代碼來源:String.Replace

輸出:

The initial string: 'aaa'
The final string: 'ddd'

示例2: stringReplace1

Class stringReplace1
   Public Shared Sub Main()
      Dim str As [String] = "1 2 3 4 5 6 7 8 9"
      Console.WriteLine("Original string: ""{0}""", str)
      Console.WriteLine("CSV string:      ""{0}""", str.Replace(" "c, ","c))
   End Sub
End Class
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:7,代碼來源:String.Replace

輸出:

Original string: "1 2 3 4 5 6 7 8 9"
CSV string:      "1,2,3,4,5,6,7,8,9"

示例3: Example

Module Example
   Public Sub Main()
      Dim s As New String("a"c, 3)
      Console.WriteLine("The initial string: '{0}'", s)
      s = s.Replace("a"c, "b"c).Replace("b"c, "c"c).Replace("c"c, "d"c)
      Console.WriteLine("The final string: '{0}'", s)
   End Sub
End Module
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:8,代碼來源:String.Replace

輸出:

The initial string: 'aaa'
The final string: 'ddd'

示例4: ReplaceTest

Public Class ReplaceTest
    
    Public Shared Sub Main()
        Dim errString As String = "This docment uses 3 other docments to docment the docmentation"
                
        Console.WriteLine("The original string is:{0}'{1}'{0}", Environment.NewLine, errString)

        ' Correct the spelling of "document".  
        Dim correctString As String = errString.Replace("docment", "document")
      
        Console.WriteLine("After correcting the string, the result is:{0}'{1}'", Environment.NewLine, correctString)
    End Sub
End Class
開發者ID:VB.NET開發者,項目名稱:System,代碼行數:13,代碼來源:String.Replace

輸出:

The original string is:
This docment uses 3 other docments to docment the docmentation'

After correcting the string, the result is:
This document uses 3 other documents to document the documentation'

示例5: MainClass

' 導入命名空間
Imports System

Public Class MainClass
    Shared Sub Main()
        'Declare variables
        Dim strData As String
        Dim strNewData As String

        'Get the text from the TextBox
        strData = "Hello You"

        'Replace the string occurance
        strNewData = strData.Replace("Hello", "Goodbye")

        'Display the new string
        System.Console.WriteLine(strNewData)
    End Sub

End Class
開發者ID:VB程序員,項目名稱:System,代碼行數:20,代碼來源:String.Replace


注:本文中的System.String.Replace方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。