VSFlexString Introduction > Replacing Demo |
This demo builds on the previous one by showing how you can modify the data after retrieving it.
Suppose the phone company decided to change all the 415 prefixes into 414, and we want to update our client list to reflect this change.
To accomplish this using the VSFlexString control, we start by locating the information we want to change, and then change it into the new value using the Replace property. Here is the code:
Example Title |
Copy Code
|
---|---|
ClientList = "John Doe: (415) 555-1212," & _ "Mary Smith: (212) 555-1212," & _ "Dick Tracy: (412) 555-1212," & _ "Martin Long: (415) 555-1212," & _ "Leo Getz: (510) 555-1212," & _ "Homer Simpson: (415) 555-1212" fs.Text = ClientList fs.Pattern = "(415)" Debug.Print fs.MatchCount " matches found." fs.Replace = "(414)" Debug.Print fs.MatchCount " matches found." Debug.Print fs |
And here is the result:
Example Title |
Copy Code
|
---|---|
3 matches found. 0 matches found. John Doe: (414) 555-1212,Mary Smith: (212) 555-1212, Dick Tracy: (412) 555-1212,Martin Long: (414) 555-1212, Leo Getz: (510) 555-1212,Homer Simpson: (414) 555-1212 |
Notice that the code prints the number of matches found twice. The first time, it reports three matches. The second time, after the Replace statement, it reports no matches. This is because as soon as the replacement takes place, all the "(415)" strings are gone, and thus there's nothing to match.