|
-
Sep 15th, 2011, 06:01 AM
#1
Thread Starter
Lively Member
[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.
-
Sep 15th, 2011, 06:12 AM
#2
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...
-
Sep 15th, 2011, 06:22 AM
#3
Thread Starter
Lively Member
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
-
Sep 15th, 2011, 10:56 AM
#4
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|