Results 1 to 5 of 5

Thread: how to read some text from this file contect

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    156

    how to read some text from this file contect

    hi
    i want to grab some text from a binary file(attached),this is content of a file.
    for example get some text between
    "p a c k a g e  m a n i f e s t" and "u s e "s - s d k". result is "c o m . k m a g i c . s o l i t a i r e  1 . 1 2 . 1"

    howto do that?


    thanks

    Code:
      Ì    ð             x              4   R   ^   l   x      ¢   ú   þ     $  P  `  t  Ž  ¢  º  Ø  è     4   v e r s i o n C o d e    v e r s i o n N a m e   
     m i n S d k V e r s i o n    i c o n    l a b e l    n a m e   
     l a u n c h M o d e    a n d r o i d   * h t t p : / / s c h e m a s . a n d r o i d . c o m / a p k / r e s / a n d r o i d        p a c k a g e    m a n i f e s t    c o m . k m a g i c . s o l i t a i r e    1 . 1 2 . 1    u s e s - s d k    a p p l i c a t i o n    a c t i v i t y   
     . S o l i t a i r e   
     i n t e n t - f i l t e r    a c t i o n    a n d r o i d . i n t e n t . a c t i o n . M A I N    c a t e g o r y     a n d r o i d . i n t e n t . c a t e g o r y . L A U N C H E R   € $               ÿÿÿÿ       `      ÿÿÿÿÿÿÿÿ                   ÿÿÿÿ  Á        
         
       ÿÿÿÿ
                8      ÿÿÿÿÿÿÿÿ                  ÿÿÿÿ            ÿÿÿÿÿÿÿÿ    L      ÿÿÿÿÿÿÿÿ                  ÿÿÿÿ          ÿÿÿÿ    `      ÿÿÿÿÿÿÿÿ                  ÿÿÿÿ                        ÿÿÿÿ      $      ÿÿÿÿÿÿÿÿ              8      ÿÿÿÿÿÿÿÿ                                 ÿÿÿÿÿÿÿÿ    8      ÿÿÿÿÿÿÿÿ                                 ÿÿÿÿÿÿÿÿ          ÿÿÿÿÿÿÿÿ          ÿÿÿÿÿÿÿÿ          ÿÿÿÿÿÿÿÿ           ÿÿÿÿÿÿÿÿ           ÿÿÿÿ   
    
    Attached Files Attached Files
    • File Type: txt 1.txt (1.4 KB, 106 views)

  2. #2
    Lively Member CADman's Avatar
    Join Date
    Aug 2007
    Posts
    92

    Re: how to read some text from this file contect

    I expect you'll have to open the file for binary, step through looking for "m a n i f e s t", save the byte position after that string, step through looking for "u s e s - s d k", save the byte position before that string, extract the text between the two byte markers, locate the non-alpha character, split the string at that character into two strings, do a REPLACE() to remove spaces (if you want) and you should have your two strings.

    Edit: I forgot, you'll also have non-alpha characters at the beginning of the first string and the end of the second string to remove.

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Feb 2009
    Posts
    156

    Re: how to read some text from this file contect

    Quote Originally Posted by CADman View Post
    I expect you'll have to open the file for binary, step through looking for "m a n i f e s t", save the byte position after that string, step through looking for "u s e s - s d k", save the byte position before that string, extract the text between the two byte markers, locate the non-alpha character, split the string at that character into two strings, do a REPLACE() to remove spaces (if you want) and you should have your two strings.

    Edit: I forgot, you'll also have non-alpha characters at the beginning of the first string and the end of the second string to remove.


    thanks but howto do this.(find my some text in binary file)
    can you show me the code?
    urgent.


    BR.

  4. #4
    Lively Member CADman's Avatar
    Join Date
    Aug 2007
    Posts
    92

    Re: how to read some text from this file contect

    Rem I haven 't tested this so you will have to tweak it some.
    Rem I am sure there is probably a more elegant way to do this
    Rem as I don't use binary much
    Code:
    Option Explicit
    Dim I As Integer
    Dim X As Long
    Dim SS As String
    Dim Temp As String
    Dim MyString As String
    Dim Mark(2) As Long
    
    Rem "m a n i f e s t" = 15 characters
    Rem "u s e s - s d k" = 15 characters
    On Error GoTo NoFileFound
    Open "yourpath\" & "Yourdatafile" For Binary As #1 'you can use freefile to get a file #
    Close #1
    On Error GoTo EndOfData
    Open "yourpath\" & "Yourdatafile" For Binary As #1
    Top:
    Input #1, Temp
    X = X + 1
    If Temp = "m" Then 'maybe we have it
        SS = m
        For I = 1 To 14 'looking for the rest of the word
            Input #1, Temp
            SS = SS & Temp
            X = X + 1
        Next
    Else
        GoTo Top
    End If
    If SS = "m a n i f e s t" Then Mark(1) = X Else GoTo Top
    Middle:
    Input #1, Temp
    X = X + 1
    MyString = MyString & Temp
    If Temp = "u" Then 'maybe we have second part
        Mark(2) = X
        SS = Temp
        For I = 1 To 14 'looking for the rest of the 2nd word
          Input #1, Temp
          MyString = MyString & Temp
          SS = SS & Temp
          X = X + 1
        Next
    End If
    If SS = "u s e s - s d k" Then GoTo Last Else GoTo Middle 'we have the data in MyString
    Last:
    Close #1
    Rem trim non-alpha and space characters
    Dim C As Integer
    For I = 1 To Len(MyString)
        C = Asc(Mid$(MyString, I, 1))
        If C < 32 Or C > 122 Then Mid$(MyString, I, 1) = " " 'replace it with a space
    Next
    MyString = Replace(MyString, " ", "") 'get rid of spaces
    Rem at this point there is no space between the letters and the numbers
    For I = 1 To Len(MyString)
        C = Val(Mid$(MyString, I, 1))
        If C <> 0 Then 'here is the first numeral
        MyString = Left$(MyString, I - 1) & " " & Mid$(MyString, I)
        Exit For
    Next
    Debug.Print MyString
    rem add error code here for the two at top

  5. #5
    Addicted Member pcuser's Avatar
    Join Date
    Jun 2008
    Posts
    219

    Re: how to read some text from this file contect

    For the sake of this post, I'll define "string" as one or more consecutive ASCII characters between 32 and 126. Here's what I use to find all ansi and unicode strings in any type of file:

    Code:
    Public Sub FindStrings(strFile As String, lngMinLength As Long)
    
    Dim strData As String
    Dim MyString As String
    Dim i As Long
    
        Screen.MousePointer = vbHourglass
        
        'If FileExists(strFile) = True Then
            Open strFile For Binary As #1
                strData = Space(LOF(1))
                Get #1, , strData
            Close #1
        'Else
        '    MsgBox strFile & " doesn't exist!"
        '    Screen.MousePointer = vbNormal
        '    Exit Sub
       ' End If
        
        ' Find ANSI Strings
        For i = 1 To Len(strData)
            If Asc(Mid(strData, i, 1)) > 31 And Asc(Mid(strData, i, 1)) < 127 Then
                If MyString = "" Then
                    MyString = Mid(strData, i, 1)
                Else
                    MyString = MyString & Mid(strData, i, 1)
                End If
            Else
                If MyString <> "" Then
                    If Len(MyString) > lngMinLength Then
                        lstStrings.AddItem MyString
                    End If
                    MyString = ""
                End If
            End If
        Next
    
        MyString = ""
        
        ' Find UNICODE Strings
        For i = 1 To Len(strData)
            If i = Len(strData) - 3 Then
                Screen.MousePointer = vbNormal
                Exit Sub
            End If
            If Asc(Mid(strData, i, 1)) > 31 And Asc(Mid(strData, i, 1)) < 127 Then
                If Asc(Mid(strData, i + 1, 1)) = 0 And Asc(Mid(strData, i + 2, 1)) = 0 And Asc(Mid(strData, i + 3, 1)) = 0 Then
                    MyString = MyString & Mid(strData, i, 1)
                    If Len(MyString) > lngMinLength Then
                        lstStrings.AddItem MyString
                    End If
                    MyString = ""
                ElseIf Asc(Mid(strData, i + 1, 1)) = 0 Then
                    If MyString = "" Then
                        MyString = Mid(strData, i, 1)
                    Else
                        MyString = MyString & Mid(strData, i, 1)
                    End If
                End If
            Else
                If MyString <> "" And Asc(Mid(strData, i, 1)) <> 0 Then
                    If Len(MyString) > lngMinLength Then
                        lstStrings.AddItem MyString
                    End If
                    MyString = ""
                End If
            End If
        Next
    
        Screen.MousePointer = vbNormal
    
    End Sub
    Put a listbox on a form (lstStrings) and call FindStrings with the full path/filename to the file you want to read the strings from and a second parameter to specify the minimum length that you want to be considered a string.

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