469,288 Members | 2,353 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,288 developers. It's quick & easy.

Finding a substring in a mainstring

Hi,
This is a simple thing, but I'm having a bit of difficulty getting it exact.
I've tried a few different codes, but can't do what I want, can some one
help please?

I have 3 text boxes, txtMainstring, txtSubstring and txtReplace string.
Using the Instr and Replace functions I am able to search for text in
txtMainString for the text in txtSubString, and then replace it with
txtReplace. There are no problems with that. But I would like it to
perform more like a 'Word Document'. When I search for a my word in
txtMainString, I want it to highlight each time it finds the word. Then I
need to replace each one (One at a time). I know I need to use SelText to
highlight them, but I'm not sure how to.

Can someone please help?

Thanks

Cassandra
Jul 17 '05 #1
4 9501
"cassandra.flowers" <ca***************@btopenworld.com> wrote
Hi,
This is a simple thing, but I'm having a bit of difficulty getting it exact.
I've tried a few different codes, but can't do what I want, can some one
help please?

I have 3 text boxes, txtMainstring, txtSubstring and txtReplace string.
Using the Instr and Replace functions I am able to search for text in
txtMainString for the text in txtSubString, and then replace it with
txtReplace. There are no problems with that. But I would like it to
perform more like a 'Word Document'. When I search for a my word in
txtMainString, I want it to highlight each time it finds the word. Then I
need to replace each one (One at a time). I know I need to use SelText to
highlight them, but I'm not sure how to.


It should be something more like this: <Find is your SubString to look for>

pos = InStr(Text1.Text, Find) - 1
If pos Then
' found
Text1.SelStart = pos
Text1.SelLength = Len(Find)
Else
' not found
End If

pos might be -1 if there is no match.
Instr supports a [Start] parameter if you need to get further into the text.

LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #2

I corrected it once, and included the -1 comment, but a bad version
got pasted into the post.

the line: If pos Then
should be: If pos < 0 Then

Sorry!
LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #3
.... I've fiddled around with it but i cant seem to get it to work. Any
ideas?

Thanks

Cassandra

"Larry Serflaten" <Fi******@RiskOfBeingSpam.med> wrote in message
news:3f********@corp.newsgroups.com...

I corrected it once, and included the -1 comment, but a bad version
got pasted into the post.

the line: If pos Then
should be: If pos < 0 Then

Sorry!
LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 17 '05 #4
> ... I've fiddled around with it but i cant seem to get it to work. Any
ideas?

Post some sample code, in a demo project. What is the problem you
are having?

LFS

-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Victor Engmark | last post: by
5 posts views Thread by richard_thomas | last post: by
5 posts views Thread by brettr | last post: by
5 posts views Thread by giampiero mu | last post: by
6 posts views Thread by Tarun | last post: by
3 posts views Thread by Solel Software | last post: by
2 posts views Thread by Badass Scotsman | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.