关于字符串截取的一个问题

sparadise1003 2011-07-20 03:50:27
字符串有如下几种可能:"3367B "或"3367B.1" 或 "3367B.1.1" 或 "3367B.1-1"大概这四种可能吧,我现在实现的功能是:如果有“.”就把第一个“.”之前的截取出来存为新字符串。
...全文
58 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
ningto.com 2011-07-20
  • 打赏
  • 举报
回复

#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
char arrDest[] = "3367B.1.1";

int i = 0;
while (arrDest[i])
{
if (arrDest[i] == '.')
{
arrDest[i] = '\0';
break;
}
i++;
}
cout << arrDest << endl;

return 0;
}
ningto.com 2011-07-20
  • 打赏
  • 举报
回复

int i = 0;
while (arrDest[i])
{
if (arrDest[i] == '.')
{
arrDest[i] = '\0';
break;
}
i++;
}
赵4老师 2011-07-20
  • 打赏
  • 举报
回复
char s[]="3367B.1-1";
char t[20],*p;
strcpy(t,s);
p=strchr(t,'.');
if (p) *p=0;
printf("[%s]\n",t);
bdmh 2011-07-20
  • 打赏
  • 举报
回复

string s = "abc.d";
int i = s.find_first_of(".");
string news = s.substr(0,i);
金刚葫芦娃 2011-07-20
  • 打赏
  • 举报
回复
char *str,*str1;
strcpy(str,"3367B.1");
str1 = strtok(str,".");
结果:str1 = 3367B

69,371

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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