社区
C语言
帖子详情
请教一字符串处理函数
yaningou
2003-10-17 10:59:55
假设有vc_str1的值为"1=12345;2=123",我要将"1="与";"之间的"12345"赋于vc_str2,
将"2="后的"123"赋于vc_str3.
当vc_str_str1的值为"1=12345"时得到vc_str2="12345",vc_str3=""
当vc_str_str2的值为""时,vc_str2="",vc_str3=""
请问该函数如何写?
...全文
43
6
打赏
收藏
请教一字符串处理函数
假设有vc_str1的值为"1=12345;2=123",我要将"1="与";"之间的"12345"赋于vc_str2, 将"2="后的"123"赋于vc_str3. 当vc_str_str1的值为"1=12345"时得到vc_str2="12345",vc_str3="" 当vc_str_str2的值为""时,vc_str2="",vc_str3="" 请问该函数如何写?
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
6 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
yaningou
2003-10-17
打赏
举报
回复
假设有vc_str1的值为"1=12345;2=123",我要将"1="与";"之间的"12345"赋于vc_str2,
将"2="后的"123"赋于vc_str3.
当vc_str_str1的值为"1=1234阿5"时得到vc_str2="12345",vc_str3=""
当vc_str_str1的值为""时,vc_str2="",vc_str3=""
请问该函数如何写?(其中vc_str1,vc_str2,vc_str3都为char型)
njuhuangmy
2003-10-17
打赏
举报
回复
这个 只是 方法
还要 注意 判断, str1 不要出界
njuhuangmy
2003-10-17
打赏
举报
回复
当vc_str_str2的值为""时,vc_str2="",vc_str3=""
1??
设字符串用的是 指针
while (*str1 != '=')
str1++;
str1++;
len = 0;
while (*str1 != ';')
str2[len++] = *str1++;
在外围再循环,可以得 str2, 当然,还要一个 整型的数 来控制 str3....
ghxmagic
2003-10-17
打赏
举报
回复
#include <stdio.h>
void main(void)
{
char *vc_str1="1=12345;2=123";
char *vc_str2;
char *vc_str3;
bool bflag,bflags;
bflag=false;
bflags=false;
vc_str2=vc_str1;
vc_str3=vc_str1;
while(*vc_str1!='\0')
{
if((*vc_str1=='1')&&(*(vc_str1+1)=='='))
{
bflag=true;
vc_str1++;
vc_str2=vc_str1++;
continue;
}
if((*vc_str1==';')&&(*(vc_str1+1)=='2')&&(*(vc_str1+2)=='='))
{
bflags =true;
bflag=false;
vc_str1+=2;
vc_str3=vc_str1;
continue;
}
if(bflag==true)
{
vc_str2++;
vc_str1++;
continue;
}
if(bflags==true)
{
vc_str3++;
vc_str1++;
continue;
}
}
}
jEditor
2003-10-17
打赏
举报
回复
#include <string.h>
using namespace std;
main()
{
string vc_str1 = "1=12345;2=123";
string sTemp = "", vcd_str2"", vc_str3 = "";
int ibegin = 0, ipos = 0, icount = 1;
for(int i = 0; i < vc_str1.length(); i++)
{
ipos ++;
if(vc_str1[i] == ";")
{
icount++;
sTemp = vc_str1.substr(ibegin + 2, ipos - 1);
switch(icount)
{
case 2:
vc_str2 = sTemp;
break;
case 3:
vc_str3 = sTemp;
break;
default:
break;
}
begin = i + 1;
ipos = 0;
}
}
}
zhyy
2003-10-17
打赏
举报
回复
int i;
char vc_str_str[3][128];
char vc_str1[128];
char s[128];
char * ps;
int j;
int off;
vc_str1 = "1=12345;2=123";
ps = NULL;
for (i=1;i<=3;i++)
{
sprintf(s,"%d=",i);
off = strlen(s);
ps = strstr(vc_str1, s);
if (ps == NULL) {vc_str_str[i][0] = 0;continue;}
memset(s, 0, sizeof(s));
for(j=0;;j++)
{
if(ps[j] == 0)
{
ps[0] = 0;
strcpy(vc_str_str[i], ps+off);
}
else if( ps[j] == ';')
{
strncpy(vc_str_str[i], ps+off, j-off-1);
strcpy(s, ps+j+1);
memset(ps, 0, sizeof(vc_str1)-(ps - vc_str1));
strcat(vc_str1, s);
}
else ;
}
}
Python将
字符串
常量转化为变量方法总结
前几天,我们Python猫交流学习群 里的 M 同学提了个问题。...打扰一下大家,
请教
一个问题,已知 list = [‘A’, ‘B’, ‘C’, ‘D’] , 如何才能得到以 list 中元素命名的新列表 A = [], B = [], C
Excel公式大全操作应用实例(史上最全)
如何把单元格中的数字提取出来(
字符串
中不连续) 数字在
字符串
中不连续如何提取数字 用如何提取“-”前后的字符 怎样删去﹕后的文字 怎样只取“.”之后的文字﹖ 获取单元格内容中
字符串
如何提取一串数字中的几位...
C++基础入门教程(三):数组、
字符串
、结构体、共用体
那么,今天就来初次介绍数组与
字符串
…以及结构体..还有共用体..吧。 1.数组 我记得大四实习的时候,
请教
同事:“什么是属主?”(其实是和数据库相关的东西) 然后同事惊讶地说道:“啊,你连数组都不知道..这,...
字符串
函数详解php,关于php
字符串
函数的详细介绍
字符串
函数stripos()是查找
字符串
在另一
字符串
中第一次出现的位置,该函数是不区分大小写的。用起来是很方便的,与其相关的函数有strripos() - 查找
字符串
在另一
字符串
中最后一次出现的位置(不区分大小写)strpos() -...
linux 拆分
字符串
函数,标准C中strtok函数分割
字符串
标准C中可以用strtok函数来分割
字符串
,strtok函数的使用与其他大部分函数的使用方法不同。函数为:char *strtok(char *strings,const char *tokseps);其中strings为要分割的
字符串
,tokseps是用来分割的字符。用...
C语言
69,382
社区成员
243,073
社区内容
发帖
与我相关
我的任务
C语言
C语言相关问题讨论
复制链接
扫一扫
分享
社区描述
C语言相关问题讨论
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章