1

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.

4 Answers 4

4

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)

Sign up to request clarification or add additional context in comments.

Comments

0

result = sampe.Replace("STAR", "BAT") is your friend...

Comments

0
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

Comments

0

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.