通过子字符串拆分字符串 [英] Split string by a substring

查看:60
本文介绍了通过子字符串拆分字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下字符串:

char str[] = "A/USING=B)";

我想拆分以获得单独的 AB 值,其中 /USING= 作为分隔符

I want to split to get separate A and B values with /USING= as a delimiter

我该怎么做?我知道 strtok() 但它只是被一个字符分割作为分隔符.

How can I do it? I known strtok() but it just split by one character as delimiter.

推荐答案

我知道 strtok() 但它只是被一个字符分割为分隔符

I known strtok() but it just split by one character as delimiter

不,不是.

根据strtok()手册页>,(强调我的)

char *strtok(c​​har *str, const char *delim);

[...] delim 参数指定一个字节集,用于分隔解析字符串中的标记.[...] 解析字符串中两个或多个连续分隔符字节的序列被视为单个分隔符. [...]

[...] The delim argument specifies a set of bytes that delimit the tokens in the parsed string. [...] A sequence of two or more contiguous delimiter bytes in the parsed string is considered to be a single delimiter. [...]

因此,它不必是您提到的一个字符".您可以使用字符串,例如在您的情况下 "/USING=" 作为分隔符来完成工作.

So, it need not be "one character" as you've mentioned. You can using a string, like in your case "/USING=" as the delimiter to get the job done.

这篇关于通过子字符串拆分字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆