Results 1 to 15 of 15

Thread: Searching a string

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Angry

    How can u search a string if it contains a certain text I specify!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Try InStr.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3
    Hyperactive Member
    Join Date
    Aug 2000
    Posts
    258
    Use Instr

    Code:
    InStr(1, Tosearchtext, "lookingfortext") ' 1 is the starting postion

    ][P
    Visual Basic 6 SP4 on win98se

    QUIT THE RAT RACE BECAUSE YOUR MESSING THE WORLD UP !!!!!

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Angry

    can u explain it's parameters like [start] and string1 and string2 and stuff like that, what do they mean
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    ok
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    string1 - string to look in
    string2 - string to search for
    start - character to begin searching from (1 = first char)
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    New Member
    Join Date
    Nov 2000
    Location
    Montreal, Canada
    Posts
    14

    Red face

    Use InStr function

    InStr([start_pos],str_to_search,search_for [,compare_type])

    Ex:

    Dim x as Integer
    Dim strToSrch as String

    strToSrch = "This is so easy..."
    x = InStr(strToSrch, "easy")

    If string was found the value of the x will be stating position of the string (in this case x=12).
    If string was not found then x=0
    File not found!
    Abort, Retry, Get a Beer...

    L8r

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    OK, what if I want it to return a word from a specific line!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You can't as such, since a logical line is terminated by a newline, not where it wraps on-screen. Try splitting the lines up, and searching individually.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  10. #10

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    This is what I mean!
    I have lets say 4 lines:

    hello there.
    My Name is VIP3R.
    I'm making a program!
    This program is not working.

    and i want my program to return VIP3R from the second line!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  11. #11
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    This might be something you need:
    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
    You'll find VIP3R by:
    msgbox RetLineWord(yourtext,2,4)
    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.

  12. #12

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Thanx

    Is there a better code. Also I have two frames in on one page and I want to get the html of one of them! How do I do that?
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Kedaman

    Try your code with a string with over 20 lines or am html page, it's not working properly. Can u please reply soon!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  14. #14
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Hmm, dunno it works well but it's a bit slow for huge texts, i did an emulation:
    Code:
    Sub main()
        For n = 1 To 105
            For s = 1 To n / 2
                d = d & "TEXT" & n & "," & s & " "
            Next s
            d = d & vbCrLf
        Next n
        Debug.Print RetLineWord(d, 100, 50)
    End Sub
    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
    What error did you get? which line?
    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.

  15. #15

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    When my text has spaces in between the lines, then the program stops right before the space! For ex:

    Hi
    This is VIP3R

    I skipped One Line
    It stop on "This is VIP3R"

    It stops on the second line because there's a double space! Try it your self!
    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