Reputation: 737
I want to create a program that could replace a specific word which I can freely set.
Sample word:
Dim sample As String = "TWINKLE TWINKLE LITTLE STAR FISH"
i want to replace the word STAR into BAT so the new output would be:
TWINKLE TWINKLE LITTLE BAT FISH
is this possible? thanks in advance.
Upvotes: 1
Views: 8691
Reputation: 11
As Tim Schmelter posted. I followed, but it not working on ignorance case. If somebody face the same problem, could follow these.
Change:
Dim regex = New Regex("STAR", RegexOptions.IgnoreCase)
sample = regex.Replace(sample, "BAT")
To:
sample = Regex.Replace(sample, "STAR", "BAT", RegexOptions.IgnoreCase)
No need Dim regex = New Regex("STAR", RegexOptions.IgnoreCase)
Upvotes: 0
Reputation: 1
Dim sample as string = "TWINKLE TWINKLE LITTLE STAR FISH"
if sample.contains("STAR") then
dim change_star as string
change_star = sample.replace("STAR","BAT")
messagebox.show("change_star")
'NOTE: output change_star
Endif
Upvotes: 0
Reputation: 460268
So you want to Replace
all occurences of one word with another?
sample = sample.Replace("STAR", "BAT")
If you want to ignore the case (.NET is case sensitive) you can use a regex:
Dim regex = New Regex("STAR", RegexOptions.IgnoreCase)
sample = regex.Replace(sample, "BAT")
(remember to add Imports System.Text.RegularExpressions
)
Upvotes: 4