本文整理匯總了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