While running a program in my server (a beacon detection code), I will receive a variable size string, named io385.
The string length can vary according to how many beacons are detected:
- One beacon: 46 bytes (first 4 bytes are useless, next 40 are important, next 2 are useless);
- Two beacons: 90 bytes (first 2 bytes are useless, next 40 are important, next 2 are useless);
- Three beacons: 134 bytes (first 2 bytes are useless, next 40 are important, next 2 are useless;
...
So, with this, my idea is to remove whatever is useless. Even though the string can vary in size, I always want to remove bytes on fixed positions (for the first beacon, first four and last 2; for the next beacons, first two and last two).
I started to manually remove the useless bytes on a 2 beacon string. However, I wanted to optimize this in order to automatically work whether the string is 46 bytes or xxxx bytes (otherwise, I'll have to manually code the character removal process for each possible string length).
string io385 = "11210000AAAA0000AAAA0000AAAA0000AAAA0A0A0A0ABF210000BBBB0000BBBB0000BBBB0000BBBB0B0B0B0BBF";
string informacao = String.Copy(io385);
informacao = informacao.Remove(0,4).Remove(40,2).Remove(40,2).Remove(80,2);
int x = io385.Length;
int y = informacao.Length;
Console.WriteLine("Original String: {0}", io385);
Console.WriteLine("Copied String: {0}", informacao);
Console.WriteLine("Original String length: {0}", x);
Console.WriteLine("Copied String length: {0}", y);