Results 1 to 11 of 11

Thread: Searching a string

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    Code:
    Function RetLineWord(ByVal str As String, linenum As Long, wordnum As Long) As String
    Dim x&, pos&, pos2&
        For x = 2 To linenum
            pos = InStr(pos + 1, str, vbCrLf)
            pos = pos + 1
        Next x
        For x = 2 To wordnum
            pos = InStr(pos + 1, str, " ")
        Next x
        pos2 = InStr(pos + 1, str, " ")
        If pos2 = 0 Then pos2 = Len(str) + 1
        RetLineWord = Mid(str, pos + 1, pos2 - pos - 1)
    End Function
    That's the code I use but if there's a doublespace between the lines in the string I give it, it doesn't return the value! Can someone modify it to ignore doublespcaes or something!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  2. #2

  3. #3
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    A few posts ago I learned it's a good idea to use the $ wherever you need string thingies...

    like mid$,left$,right$,instr$ and so on...
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    MartinLiss

    Can you explain what that does to my code! Thanx for you reply!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    It replaces all the double spaces ( ) with one space ( )
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Why don't you ask me to maintain the code first? since i know how my own code works..
    Code:
    Function RetLineWord(ByVal str As String, linenum As Long, wordnum As Long) As String
    Dim x&, pos&, pos2&
        For x = 2 To linenum
            pos = InStr(pos + 1, str, vbCrLf)
            pos = pos + 1
        Next x
        lastspace = -1
        For x = 2 To wordnum
            pos = InStr(pos + 1, str, " ")
            If pos - lastspace <= 1 Then x = x - 1
            pos2 = InStr(pos + 1, str, " ")
            If pos2 - pos = 1 Then x = x - 1
        Next x
        If pos2 = 0 Then pos2 = Len(str) + 1
        RetLineWord = Mid(str, pos + 1, pos2 - pos - 1)
    End Function
    Should work with any amount of blank spaces
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Hey Keda/Kado/Kadi.. come over to ICQ friend
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Angry KedaMAN

    It doesn't work!!! Try it out your self before you give it to me please.
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  9. #9
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    I've noticed this gets more and more complicated as i work on it, so i thought about approach it in another way. Do you need to use this for the same text over and over again? In that case, do you do it in some kind of order? Can the text change`?
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  10. #10
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Worldwide in the Sun
    Posts
    566
    Hallo,

    Try this

    *********************************

    Dim MyIndex
    Dim MyArray(3)
    Dim Srchtext
    Dim Position

    ' your text
    MyArray(0) = Text1.text
    MyArray(1) = Text2.text
    MyArray(2) = Text3.text
    MyArray(3) = Text4.text

    ' text to find in your text
    Srchtext= Text5.text

    ' selection to find the string
    MyIndex = filter(MyArray, Srchtext)

    ' Startposition srchtext
    Position = Instr(1, MyIndex(0), Srchtext)

    MsgBox = (" String = " & MyIndex(0))
    MsgBox = ("Startposition = " & Position)

    ****************************************

    Create a form witk 5 textboxes and a cmdbutton
    put the code in the cmdbutton

    Cheers
    Ray
    Ray

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    Yeah, I usually get the HTMl of a page wich changes every 20 seconds, but the text barely changes, it's only like 10 words that change!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width