X



Home>Tutorial>

String.Equals, String.Replace, and String.Insert Methods in Visual Basic

Nuelson Penuel Sunday, September 13, 2020 Visual Basic.Net

Summary

In this post, am going to show you String.Equals,String.Replace, and String.Insert Methods in Visual Basic

VB.Net Equals Method

The Equals() method can be used in place of the "=" when comparing one string against another. If the comparison has a match, true will be returned while false if no match found.

Equals Method Syntax

It has the following syntax;
String.Equals(expression)

String.Equals Method Example


If dURL.Equals("www.emmason247.com.ng") Then

    MessageBox.Show()

   Else

   MessageBox.Show("No match found")

End If
You might also like Visual Basic Substring

VB.Net Replace Method

The replace method is mostly used when you want to replace text in one string with some another text. The process is fairly straightforward.

Replace Method Syntax

It has the following syntax

String.Replace(Expression, Replacement)
In the Replace method syntax, Expression means the text that contains what you intend to replace why the Replacement means replacement string

String.Replace Method Example

Here's some code that uses replace. Add a button to a form and test it out:

Dim str As String = "Welcome to Emmason"
str = str.Replace( "Emmason", "Emmason Community" )
MessageBox.Show(str)

If you run the code now, you will see a message box saying"Welcome to Emmason Community" instead of "Welcome to Emmason" You can also check Split() in VB

VB.Net Insert Method

The visual basic Insert () method is used to insert new text into an existing text.

String.Insert Method Syntax

String.Insert(startIndex, newText)
The start index means where the method will start is positioning from while new Text is the text that is to be inserted

VB.Net String.Insert Method Example

Dim str As String = "I Emmason247.com.ng"
str = str.Insert(2, "love")
MsgBox(str)
Output
I love Emmason247.com.ng
The 2 in round parenthesis means start at position 5 in the string variable str (the count starts at zero).

| | Views(988)

See Demo | Download File


Add your comment. Indicate code using code tag


Words: 0 | Chars: 0 | Reading Duration: 0



Images Attachment




Emmason Integratded Services(2017-2024)
All Rights Reserved
Designed and Maintained By Emmason Integrated Services