Split Question

I need splitting a file for get any info

I wrote this Code:

 

Dim number As Integer = 0

Dim ParamSeparator() As Char = {"G", "I", "F", "8", "9", "a"}

Dim gif As String = File.ReadAllText(OpenFileDialog1.FileName)

Dim i As Integer = 0

For Each files As String In gif.Split(ParamSeparator)

If files.Length > 0 Then

ListBox1.Items.Add(i & " " & files.Length + 6 & " 0")

i = i + files.Length + 6

number = number + 1

End If

Next

TextBox1.Text = number

 

And it work but i have a problem with "ParamSeparator".

My problem is that if i have a file with this Text:

GIF89a11GGIF89a32

The G doesn't go counted because it is a "Char" of "ParamSeparator" but i need that ParamSeparator must be complete of all char so if i have only "GIF" it is isn't a separator but only  if there is the word "GIF89a".

How can i solve



Answer this question

Split Question

  • Lucia_fernadez

    There is none. You have to manually iterate over the byte array and start checking for 'G'. If you found a 'G' check if the next is 'I' otherwise look for the next 'G', if it was 'I' check the next for 'F' and so on.

    You might also look for a graphics library which can work with GIF files and do the page splitting or whatever for you.

    --
    SvenC


  • Peter Haik

    Your going to need to read binary files using the readallbytes method

    http://msdn2.microsoft.com/en-gb/library/system.io.file.readallbytes.aspx

    Dim a As Byte() = System.IO.File.ReadAllBytes(OpenFileDialog1.Filename)

    and now you have a byte array which you need to process.


  • Ofir Epstein

    I knew it

    But i can't use Method Split Wiht ReadAllBytes.


  • alex china

    Your somewhat beating around the bush telling us what you've tried but not too clear on the overall details of the problem.   Perhaps you can provide some more details.

    As far as I can tell.     You have a file which is a binary file (not a text file) that contains some data  and your trying to extract out some information.   

    What exactly is the file format ( if we know the format of the file then we may be able to suggest a better approach to getting at the information).  Your original details showed G as a delimiter which is strange as G is also allowed as part of the the info in the file. 

    String.Split Method 

    Returns a String array containing the substrings in this instance that are delimited by elements of a specified Char or String array.

     

    This method is for dealing with strings, it looks like you dealing with binary data in a file and I'd probablu suspect it contained more than just the text your showing in the original example extract.

     


  • Fata1Attack

    That Split overload takes two params, the second is StringSplitOptions. You might want to use it like so:

    For Each files As String In gif.Split(ParamSeparator, StringSplitOptions.None)

    --
    SvenC


  • Seppe001

    It works but with Binary Files it didn't works.

    How do i edit the code for making work with Binary Files


  • Winanjaya

    But it takes this error:

    Error 1 Value of type '1-dimensional array of String' cannot be converted to 'Char'.


  • Prince of Dhump

    I tried many way but it continues to don't work with BINARY FILES.

    , so can someone can post me a sample code for splitting binary files Thanks


  • AndrasEliassen

    The files that i have to manage is a file made by many gif merged into one file.

    So now what can i do


  • Helen999888

    The problem is this line:

    Dim gif As String = File.ReadAllText(OpenFileDialog1.FileName)

    Because with Binary Files it didn't work, have you any ideas


  • StephenJr

    I didn't find a good way, I read MSDN but i didn't find anything about Binary Files Splitting.
  • Minetta

    Can you give me a sample code of splitting binary files in way that you have explain in your post


  • jchewning

    Hi,

    you can use another overload of the Split method which takes a String() param:

    Dim ParamSeparator() As String = {"GIF89a"}

    --
    SvenC


  • Split Question