Finding a substring in a mainstring

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • cassandra.flowers

    #1

    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


  • Larry Serflaten

    #2
    Re: Finding a substring in a mainstring

    "cassandra.flow ers" <cassandra.flow ers@btopenworld .com> wrote[color=blue]
    > 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.
    >[/color]

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

    pos = InStr(Text1.Tex t, 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! =-----

    Comment

    • Larry Serflaten

      #3
      Re: Finding a substring in a mainstring


      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! =-----

      Comment

      • cassandra.flowers

        #4
        Re: Finding a substring in a mainstring

        .... I've fiddled around with it but i cant seem to get it to work. Any
        ideas?

        Thanks

        Cassandra

        "Larry Serflaten" <Filtered@RiskO fBeingSpam.med> wrote in message
        news:3fba6f06_5 @corp.newsgroup s.com...[color=blue]
        >
        > 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! =-----[/color]


        Comment

        • Larry Serflaten

          #5
          Re: Finding a substring in a mainstring

          > ... I've fiddled around with it but i cant seem to get it to work. Any[color=blue]
          > ideas?[/color]


          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! =-----

          Comment

          Working...