Results 1 to 4 of 4

Thread: [RESOLVED] Remove byte from bytearray.

  1. #1

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Resolved [RESOLVED] Remove byte from bytearray.

    I need to remove byte where value is 0 from a byte array.
    Please help..

    Code:
    byte[] newArray = oldArray.Where(b => b != 0xff).ToArray();
    this removing the first position,
    Visual Studio.net 2010
    If this post is useful, rate it


  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Remove byte from bytearray.

    If you want to remove elements where the value is equal to 0 then why are you telling it to remove elements where the value is not equal to 255?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3
    Cumbrian Milk's Avatar
    Join Date
    Jan 2007
    Location
    0xDEADBEEF
    Posts
    2,448

    Re: Remove byte from bytearray.

    The code you show filters the old array for all values that are not equal to 255 (0xff).
    If you want to filter out 0's use b => b != 0.

    Edit, oops bit slow (got carried away playing with lambda)
    W o t . S i g

  4. #4

    Thread Starter
    Fanatic Member vijy's Avatar
    Join Date
    May 2007
    Location
    India
    Posts
    548

    Re: Remove byte from bytearray.

    Quote Originally Posted by jmcilhinney View Post
    If you want to remove elements where the value is equal to 0 then why are you telling it to remove elements where the value is not equal to 255?
    No, actually i don't know the meaning of that code, when i surfed in net for removing byte from byte array.. i got something like above.. so that i tried and copied here..

    i used RemoveAll(Predicate<T> match), its working fine.

    i have to learn linq its reducing much steps..

    byte[] newArray = oldArray.Where(b => b != 0).ToArray();

    its simple rather than using list.

    thanks milk,
    Visual Studio.net 2010
    If this post is useful, rate it


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