"<Notify>\nUnregistered={“tml_id”:“HT057” \n} \n</Notify>_$"怎么用c语言去获取到这个字符串中的Unregistered={“tml_id”:“HT057” \n}
时间: 2024-02-20 22:02:34 浏览: 28
你可以使用 C 语言中的字符串处理函数来获取这个字符串中的 Unregistered={“tml_id”:“HT057”}。以下是一个示例代码:
```c
#include <stdio.h>
#include <string.h>
int main() {
char str[] = "<Notify>\nUnregistered={“tml_id”:“HT057” \n} \n</Notify>_$";
char *start = strstr(str, "Unregistered={");
if (start != NULL) {
char *end = strchr(start, '\n');
if (end != NULL) {
int length = end - start - strlen("Unregistered={");
char result[length + 1];
strncpy(result, start + strlen("Unregistered={"), length);
result[length] = '\0';
printf("%s\n", result);
}
}
return 0;
}
```
这段代码首先使用 `strstr` 函数查找字符串中第一次出现 "Unregistered={" 的位置,如果找到了,就使用 `strchr` 函数查找该位置后面的第一个换行符 '\n' 的位置。然后,根据这两个位置计算出需要提取的子字符串的长度,并使用 `strncpy` 函数将子字符串复制到另一个字符数组中。最后,将该字符数组输出即可。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.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)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)