[RESOLVED] Replace the first occurrence of the word in text
ok have a list of 84000 words , and have some articles in these articles i want to replace first occurrence of each word i have in listbox e.g
Code:
For Each item In ListBox1.Items
Dim mytext As String = "My some text this text is very long text and i want to replace this"
If ListBox1.Items.Contains(mytext) Then
mytext = Replace(mytext, mytext, "String to replace")
End If
Next
but it used to replace the whole mytext i want to replace words in mytext and also it hang the system and very very slow and replace all occurrences i want to replace just the first occurrence any help or idea please.
Re: Replace the first occurrence of the word in text
To replace the first occurrence use:
vb Code:
mytext = Replace(mytext, mytext, "String to replace", 1, 1)
To replace the first two occurrences use:
vb Code:
mytext = Replace(mytext, mytext, "String to replace", 1, 2)
etc...
Re: Replace the first occurrence of the word in text
Thanks. how to search for the word from listbox? problem is i have 84000 words in listbox so it take too much time for each word
Re: Replace the first occurrence of the word in text
try this:
vb Code:
Dim mytext As String = "My some text this text is very long text and i want to replace this"
For Each item In ListBox1.Items
If mytext.Contains(item.ToString) Then
mytext = Replace(mytext, item.ToString, "replacement text", , 1)
End If
Next