vc中字符串截取问题?

yjftwo 2007-10-15 07:07:53
我获得一个字符串str1="F55,F57,F59,F60,F63,F73,F74,"中间使用逗号隔开的,如何把F55 F57 F59 F60 F63 F73 F74一个一个的提取出来。谢谢!
...全文
193 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
yafizyh 2007-10-15
  • 打赏
  • 举报
回复
str1="F55,F57,F59,F60,F63,F73,F74,"
char ch[4];
ch[3]='\0';
for(char*p=str1,int i=0;(i+3)<=strlen(str1);i+=4)
{
strncpy(ch,p,3);//参数顺序记不清了。
cout<<ch<<endl;
}
hongyi1230 2007-10-15
  • 打赏
  • 举报
回复
void AFXAPI AfxFormatStrings(CString& rString, LPCTSTR lpszFormat,
LPCTSTR const* rglpsz, int nString);
hongyi1230 2007-10-15
  • 打赏
  • 举报
回复
void AFXAPI AfxFormatStrings(CString& rString, LPCTSTR lpszFormat,
LPCTSTR const* rglpsz, int nString);
星光伴月 2007-10-15
  • 打赏
  • 举报
回复
这是一个替换函数,你可以参考一下:

void replaceAll(std::string& context,const std::string & from, const std::string & to)
{
size_t look = 0;
size_t found;
while((found = context.find(from,look))!=string::npos)
{
context.replace(found,from.size(),to);
look=found+to.size();
}
}

0黄瓜0 2007-10-15
  • 打赏
  • 举报
回复

int main()
{
const char*str="F55,F57,F59,F60,F63,F73,F74,";
char s[8][10];
int i=0,j=0,k=0;
for(;i<7;++i)
{
k=0;
while(1)
{
if(str[j] != ',')
{
s[i][k]=str[j];
++k;
++j;
}
else
{
s[i][k]=0;
++j;
break;
}
}
}

for(i=0;i<7;++i)
printf("%s\n",s[i]);

}
iu_81 2007-10-15
  • 打赏
  • 举报
回复
#include <iostream>
#include <string>
using namespace std;

int main()
{
string str1="F55,F57,F59,F60,F63,F73,F74";
char *p;

p= strtok(str1,",");
while(p)
{
printf("%s\n",p);
p = strtok(NULL, ",");
}

return 0;
}
iu_81 2007-10-15
  • 打赏
  • 举报
回复
strtok

64,637

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧