|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
replacing charsHi,
I habe a binary file which I load into a byte array. I have to change some byte to another, for e.g. if byte = 101 then must be 122. It is about 100 such changes. I can make 100 "if" or 100 "select case". is there any other better method to do it (some structure data in which I could keep my dictionary like array list, hashtable, stack and to which it would be easy to imput my dictionary) Thanks. Przemo Hello Przemo,
>I habe a binary file which I load into a byte array. I have to change some I don't quite understand the last part, where you make a suggestion >byte to another, for e.g. if byte = 101 then must be 122. It is about 100 >such changes. I can make 100 "if" or 100 "select case". >is there any other better method to do it (some structure data in which I >could keep my dictionary like array list, hashtable, stack and to which it >would be easy to imput my dictionary) yourself - it's possible that you're on a good track there. My suggestion would be to use a mapping structure, in this case an array might be good as you have a pretty restricted value range. Somewhat like this: byte[] mapping = new byte[256] { 0, 1, 2, 3, 11, ... // list all 256 mapped values }; And then you could map like this: byte originalValue = ...; byte newValue = mapping[originalValue]; For more complex cases (i.e. when there are a lot more than 256 values, or when the value range isn't clear at all), you could instead use a Dictionary, like this: Dictionary<int, int> mapping = new Dictionary<int, int>( ); mapping[5] = 11; int originalValue = ...; int newValue = mapping.ContainsKey(originalValue) ? mapping[originalValue] : originalValue; Oliver Sturm |
|||||||||||||||||||||||