Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / December 2006

Tip: Looking for answers? Try searching our database.

replacing a smaller string within a larger string

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Larry - 16 Dec 2006 18:37 GMT
If there is a smaller string in a larger string, I want to delete the
smaller string.  Is it possible to do this?  I've tried simply making
smallString = "", but that hasn't worked yet.

' Test code

mainString = Selection.Text
smallString = "HELLO"

If InStr(mainString, smallString) > 0 Then
' What?

Thanks.
Jay Freedman - 16 Dec 2006 19:16 GMT
Use the Replace function, replacing the small string with nothing:

 Selection.Text = Replace(Selection.Text, smallString, "")

If the small string doesn't occur in the selection, nothing will
happen (strictly speaking, the selection is replaced with itself). If
the small string occurs one or more times, all occurrences will be
removed at once.

The Replace function isn't available in Word 97 VBA, so if you need to
support that version, look in Google Groups for a way to write a
function that does the same thing.

--
Regards,
Jay Freedman
Microsoft Word MVP        FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.

>If there is a smaller string in a larger string, I want to delete the
>smaller string.  Is it possible to do this?  I've tried simply making
[quoted text clipped - 9 lines]
>
>Thanks.
Larry - 19 Dec 2006 01:58 GMT
Thanks Jay.

Larry

> Use the Replace function, replacing the small string with nothing:
>
[quoted text clipped - 29 lines]
> >
> >Thanks.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.