在c#中从53 30 32 32 33 32 36 31 37 32 36 30 0D 中判断0D标识并取出S02232617260
时间: 2024-04-12 13:28:28 浏览: 26
在C#中,你可以使用以下代码来判断并提取出0D标识后的字符串:
```csharp
string data = "53 30 32 32 33 32 36 31 37 32 36 30 0D";
string[] hexArray = data.Split(' ');
int startIndex = -1;
int endIndex = -1;
for (int i = 0; i < hexArray.Length; i++)
{
if (hexArray[i] == "0D")
{
startIndex = i + 1;
break;
}
}
if (startIndex != -1)
{
StringBuilder sb = new StringBuilder();
for (int i = startIndex; i < hexArray.Length; i++)
{
if (hexArray[i] == "0D")
{
endIndex = i;
break;
}
sb.Append((char)Convert.ToInt32(hexArray[i], 16));
}
if (endIndex == -1)
{
endIndex = hexArray.Length;
}
string result = sb.ToString();
Console.WriteLine(result);
}
else
{
Console.WriteLine("0D标识未找到");
}
```
这段代码首先将字符串拆分为十六进制数组,并使用循环查找第一个0D标识的位置。然后,使用StringBuilder逐个转换为字符,并将其添加到一个字符串中,直到遇到第二个0D标识或数组末尾。最后,打印出提取出来的字符串"S02232617260"。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![rar](https://img-home.csdnimg.cn/images/20210720083606.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)