Programming Tutorials

String Insert, index off & format in VB.net

By: Issac in VB.net Tutorials on 2009-01-30  

Here are some examples of String Insert, IndexOf, and Format in VB.NET:

  1. String Insert:

The String Insert function is used to insert a string at a specified position in another string.

Example:

Dim str1 As String = "Hello"
Dim str2 As String = "World"
Dim result As String = str1.Insert(5, " " & str2)
' Output: "Hello World"
  1. IndexOf:

IndexOf method returns the position of a specified substring in a given string.

Example:

Dim str As String = "The quick brown fox jumps over the lazy dog"
Dim index As Integer = str.IndexOf("brown")
' Output: 10
  1. Format:

The Format function is used to format a string by inserting values into placeholders.

Example:

Dim name As String = "John"
Dim age As Integer = 30
Dim result As String = String.Format("My name is {0} and I am {1} years old.", name, age)
' Output: "My name is John and I am 30 years old."





Add Comment

* Required information
1000

Comments

No comments yet. Be the first!

Most Viewed Articles (in VB.net )

Latest Articles (in VB.net)