在我的服务器中运行程序(信标 检测代码)时,我将收到一个可变大小的字符串,名为io385。
字符串长度可以根据检测到的信标数量而有所不同:
- 一个信标:46 字节(前 4 字节无用,接下来 40 字节很重要,接下来 2 字节无用);
- 两个信标:90 个字节(前 2 个字节无用,接下来 40 个很重要,接下来 2 个无用);
- 三个信标:134 个字节(前 2 个字节无用,接下来 40 个重要,接下来 2 个无用;
...
所以,有了这个,我的想法是删除任何无用的东西。即使字符串的大小可能不同,我总是想删除固定位置的字节(对于第一个信标,前四个和最后两个;对于下一个信标,前两个和最后两个)。
我开始手动删除 2信标字符串上的无用字节。但是,我想对此进行优化,以便无论字符串是 46 字节还是 xxxx 字节都可以自动工作(否则,我将不得不为每个可能的字符串长度手动编码字符删除过程)。
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);