当前位置: 首页>>代码示例>>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;未经允许,请勿转载。