none
How to delete from byte [ ] RRS feed

  • Question

  • I have a question
    i convert sound wave to byte of array
    I want to delete some data from this byte [ ]
    How can i do thingss like that
    this is my code
    FileStream fs = new FileStream(@ path, FileMode.Open, FileAccess.Read) ;
    byte[] arrfile = new byte[fs.Length ];
    fs.Read(arrfile, 0, arrfile.Length) ;
    fs.Close();

    How to delete from this byte
    Sunday, January 20, 2008 11:17 AM

Answers

  • List<byte> list;

     

    using (FileStream fs = new FileStream("", FileMode.Open, FileAccess.Read))

    {

    byte[] arrfile = new byte[fs.Length];

    fs.Read(arrfile, 0, arrfile.Length);

    list = new List<byte>(arrfile);

    }

    // delete the 4th element, for example

    list.RemoveAt(3);

    // and so on

    // ...

    // convert the list back to a byte array, if needed

    byte[] resultArr = list.ToArray();

     

    Sunday, January 20, 2008 11:31 AM
  • This will delete Length bytes beginning at Index from a binary file. The result is stored in a Byte array the size of the file minus the Length of the bytes deleted.

    Code Block

    public byte[] DeleteFromArray(int Index, int Length, string FileName)

    {

    byte[] ByteArray = System.IO.File.ReadAllBytes(FileName);

    Array.Copy(ByteArray, Index + Length, ByteArray, Index, ByteArray.Length - Index - Length);

    Array.Resize(ref ByteArray, ByteArray.Length - Length);

    return ByteArray;

    }

     

     

    Sunday, January 20, 2008 12:51 PM

All replies

  • List<byte> list;

     

    using (FileStream fs = new FileStream("", FileMode.Open, FileAccess.Read))

    {

    byte[] arrfile = new byte[fs.Length];

    fs.Read(arrfile, 0, arrfile.Length);

    list = new List<byte>(arrfile);

    }

    // delete the 4th element, for example

    list.RemoveAt(3);

    // and so on

    // ...

    // convert the list back to a byte array, if needed

    byte[] resultArr = list.ToArray();

     

    Sunday, January 20, 2008 11:31 AM
  • This will delete Length bytes beginning at Index from a binary file. The result is stored in a Byte array the size of the file minus the Length of the bytes deleted.

    Code Block

    public byte[] DeleteFromArray(int Index, int Length, string FileName)

    {

    byte[] ByteArray = System.IO.File.ReadAllBytes(FileName);

    Array.Copy(ByteArray, Index + Length, ByteArray, Index, ByteArray.Length - Index - Length);

    Array.Resize(ref ByteArray, ByteArray.Length - Length);

    return ByteArray;

    }

     

     

    Sunday, January 20, 2008 12:51 PM