473,387 Members | 1,606 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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 9582
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Victor Engmark | last post by:
When looking for a method to fetch unique elements and counting the number of occurences of each of them, I found quite a lot of gross examples of complex XSL. But after realizing the subtle...
5
by: richard_thomas | last post by:
Hi, I'm having trouble running the following query: select * from message where text_body like ' ----------%' ie, five spaces followed by at least ten hyphens. The query doesn't...
5
by: brettr | last post by:
When I reference document.cookie, there is a long string of key=value; pairs listed. I may have 100 hundred cookies on my hard drive. However, most only have one key=value pair. Does the...
5
by: giampiero mu | last post by:
hi everyone my target is implement a function controlla(string - a binary string-) that check if there is in a string two equal not overlapping subsequences at least of length limitem: my...
6
by: Tarun | last post by:
Hi All, I need to find a particular substring in a binary string(some text appended & prepended to binary data). I cant use strstr since it terminates on receiving '\0'which can be there in...
3
by: Solel Software | last post by:
Hello, If I have a string "Mr. Bill Gates" stored as an nvarchar variable how would I split it into two strings "Mr. Bill" and "Gates" using T-SQL? I assume I could use Substring but to use that...
2
by: Badass Scotsman | last post by:
Hello, Using VB and ASP,NET I would like to be able to search a STRING for a smaller STRING within, based on the characters which appear before and after. For example: String1 = " That was...
2
by: Extremest | last post by:
Here is the code I have so far. It connects to a db and grabs headers. It then sorts them into groups and then puts all the complete ones into another table. Problem I am having is that for some...
2
by: jewel87 | last post by:
Hello, I've got a problem and would appreciate any help. I have to count the number of integers in a string like this "1.1 some text. 1.2 some text", where it should return 0, as there are no...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.