Detect and replace in a String

Posted on 2003-03-05
Medium Priority
Last Modified: 2010-05-01
looking for a bit of code that would find all of "Teh" and replace it with "The"
(and no i dont need a spell checker)
Question by:gthgb
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 14

Expert Comment

ID: 8071087

YourString = Replace (YourString,"teh","the")
LVL 14

Expert Comment

ID: 8071091
StringReplaced = Replace("The string to search in", "Teh", "The")
MsgBox StringReplaced
LVL 14

Accepted Solution

aelatik earned 400 total points
ID: 8071128
OK, these method will cause problems with words containing
'Teh', use the following function to avoid that problem.

Private Sub Form_Load()
MsgBox CheckForThe("Teh word to split is here in Teheran")
End Sub
Function CheckForThe(StringToCheck As String)
    WordArray = Split(StringToCheck, " ")
        For Each Word In WordArray
            If Word = "Teh" Then Word = "The"
            Result = Result & Word & " "
            CheckForThe = Result
End Function


Author Comment

ID: 8071161
overkill :) thanks

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question