本文整理汇总了VB.NET中System.String.Insert方法的典型用法代码示例。如果您正苦于以下问题:VB.NET String.Insert方法的具体用法?VB.NET String.Insert怎么用?VB.NET String.Insert使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.String
的用法示例。
在下文中一共展示了String.Insert方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
Public Module Example
Public Sub Main()
Dim original As String = "aaabbb"
Console.WriteLine("The original string: '{0}'", original)
Dim modified As String = original.Insert(3, " ")
Console.WriteLine("The modified string: '{0}'", modified)
End Sub
End Module
输出:
The original string: 'aaabbb' The modified string: 'aaa bbb'
示例2: Example
Public Class Example
Public Shared Sub Main()
Dim animal1 As String = "fox"
Dim animal2 As String = "dog"
Dim strTarget As String = String.Format("The {0} jumps over the {1}.",
animal1, animal2)
Console.WriteLine("The original string is: {0}{1}{0}",
Environment.NewLine, strTarget)
Console.Write("Enter an adjective (or group of adjectives) " +
"to describe the {0}: ==> ", animal1)
Dim adj1 As String = Console.ReadLine()
Console.Write("Enter an adjective (or group of adjectives) " +
"to describe the {0}: ==> ", animal2)
Dim adj2 As String = Console.ReadLine()
adj1 = adj1.Trim() + " "
adj2 = adj2.Trim() + " "
strTarget = strTarget.Insert(strTarget.IndexOf(animal1), adj1)
strTarget = strTarget.Insert(strTarget.IndexOf(animal2), adj2)
Console.WriteLine("{0}The final string is:{0}{1}",
Environment.NewLine, strTarget)
End Sub
End Class
' Output from the example might appear as follows:
' The original string is:
' The fox jumps over the dog.
'
' Enter an adjective (or group of adjectives) to describe the fox: ==> bold
' Enter an adjective (or group of adjectives) to describe the dog: ==> lazy
'
' The final string is:
' The bold fox jumps over the lazy dog.
示例3: MainClass
' 导入命名空间
Imports System
Imports System.Collections
Public Class MainClass
Shared Sub Main()
Dim s1 As String = "abcd"
Dim s2 As String = "ABCD"
Dim s3 As String = "Liberty Associates, Inc. provides "
s3 = s3 & "custom .NET development"
Dim s5 As String = String.Copy(s2)
Console.WriteLine("s5 copied from s2: {0}", s5)
Dim location As Integer = s3.IndexOf("provides")
Dim s10 As String = s3.Insert(location, "usually ")
Console.WriteLine("s10: {0}", s10)
End Sub
End Class