|
-
Apr 14th, 2010, 08:46 PM
#1
Thread Starter
New Member
Replace an Occurence in a String
Does anyone know how I can fix this:
I'm trying to use some sort of loops, either nested loops perhaps to get VB to go through a single string;
For example - S = "His name is Josh Howard. Josh is a great athlete. "
and I want the program to be able to find the word "Josh" and replace it with "Joe" instead. I'm trying to break the S string into three substrings, the first one is the text before the occurrence, the 2nd is the word "Joe", the 3rd being the text after the change. Make them equal S and continue the search.
Any ideas.... I solved it using the replace method so yes i know, but I figure you have to be able to solve this with just strings, the indexOF, and Length methods.
Here is my loop section of the code:
S = txtinput.text ' the inputted string (His name is Josh Howard. Josh is a great athlete)
LenS = S.Length
For p = 0 To LenS - 1
'S2 = S.Substring(i, LenS)
AVP = S.IndexOf("Academic Vice President")
' N = S.Substring(AVP + 23, LenS - 1)
S2 = S.Substring(i, AVP)
i = AVP + 23
'i =
S3 = S2 + S1
'S3 = S3.Substring(AVP + 23, )
Next
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
|