Results 1 to 8 of 8

Thread: Return a word from a string!

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Angry

    Hey sup? My problem is this: I use an Inet control to retrieve a page's HTML and then I need a code to return a word from a line in that HTML. For example I have this HTML code:
    Code:
    <HTML>
    <HEAD>
    <Title>Hey</Title>
    </Head>
    
    <Body>
    Page content
    </BOdy>
    </HTML>
    and I want to retrieve the word "Page" by using it's coordinates. By coordinates I mean it's line number and word number! When I use the function with the parameters of Line 6 and Word 1, I want it to return the word "Page"! Does anyone know how I can do that! I had a code before but it didn't work properly! Can you please see if your code works before you give it to me, because this program takes very long to load and running it many times with a bad coad may cause any system to restart or freeze! Thanx for your help in advance!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879

    Unhappy

    Doesn't anyone know how!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  3. #3
    Guest
    Make so that your code skips everything until it comes to <BODY>. Save the position to long after <BODY>. Then look for </BODY>. Save it's position to long. Cut the area in to string.

    It's better if you code this one yourself, it's not fun to copy everything and not to think yourself

    Hope this helps,

  4. #4
    Guest
    Use a RichTextBox and take a look at it's Find property in the Object Browser.

  5. #5
    Guest
    I got a example of how you can find your line.
    But you have to start with line zero of counting the lines.
    Code:
    Private Function GetLine(iLine As Integer, FileName As String) As String
    
      On Error GoTo Err_ReadFile
    
      Dim sLine As String
      Dim Infile As Integer
      Dim LineCount As Integer
          
      LineCount = 0
          
      Infile = FreeFile
      ' Open the file for reading
      Open (FileName) For Input As Infile
      ' Check if there are any data aviable the file
      If EOF(Infile) = True Then GoTo Err_ReadFile
      ' Read all the lines in the file
      Do Until EOF(Infile)
        Line Input #Infile, sLine
        If LineCount = iLine Then
          Exit Do
        End If
        LineCount = LineCount + 1
      Loop
      
      ' Well we got our string from the selected line.
      GetLine = sLine
          
      ' Close the file
      Close Infile
          
      Exit Function
      
    Err_ReadFile:
          
      ' Close the file.
      Close Infile
    
    End Function
    USe this function to find your line ( "like 6" ).
    Code:
    Dim myLine As String
    ' The rest is up to you.. :-) of finding the right word.
    myLine = GetLine(6, "C:\Test.html")
    Goodluck.


    [Edited by kayoca on 11-09-2000 at 11:53 AM]

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    Can anyine else give me a better code!
    Visual Basic 6.0
    Visual C++ 5
    Delphi 5


  7. #7
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Might be a bit more bugfree than the last one i posted
    Code:
    Function Retlineword(Text As String, line As Long, word As Long)
        Dim lines() As String, words() As String, buffer As String, x&, n&, max&
            If Len(Text) Then
                lines = Split(Text, vbCrLf)
                If line - 1 <= UBound(lines) Then
                    If Len(lines(line - 1)) Then
                        words = Split(lines(line - 1), " ")
                        max = UBound(words)
                        If word <= max Then
                            For x = 0 To max
                                If n > max Then Exit For
                                If n <> x Then words(x) = words(n)
                                If words(x) = vbNullString Then x = x - 1 
                                n = n + 1
                                
                            Next x
                            ReDim Preserve words(x)
                            If word <= x Then
                                Retlineword = words(word - 1)
                            End If
                        End If
                    End If
                End If
            End If
    End Function
    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.

  8. #8

    Thread Starter
    Fanatic Member
    Join Date
    Aug 2000
    Posts
    879
    thnx
    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