当前位置: 技术问答>linux和unix
在线等,关于取得分隔字符串的问题,给分
来源: 互联网 发布时间:2016-03-05
本文导语: 比如有一个字符串 S0101001_200809 我要取得分隔线前后的两个字符,如何做啊? #include #include int main(void) { char string[16]; char start_time[16]; char kikai_num[16]; char * s,*t, c = '_'; int scnt = ...
比如有一个字符串 S0101001_200809
我要取得分隔线前后的两个字符,如何做啊?
#include
#include
int main(void)
{
char string[16];
char start_time[16];
char kikai_num[16];
char * s,*t, c = '_';
int scnt = 0;
int tcnt = 0;
strcpy( string, "S0101002_200812");
s = strrchr(string,'_');
scnt = strlen(s+1);
memcpy(start_time,s+1,scnt);
|
这样只取得了后面的,如何取得 “_”前面的字符串阿,急~~~~~~~~写了,给分的
我要取得分隔线前后的两个字符,如何做啊?
#include
#include
int main(void)
{
char string[16];
char start_time[16];
char kikai_num[16];
char * s,*t, c = '_';
int scnt = 0;
int tcnt = 0;
strcpy( string, "S0101002_200812");
s = strrchr(string,'_');
scnt = strlen(s+1);
memcpy(start_time,s+1,scnt);
|
这样只取得了后面的,如何取得 “_”前面的字符串阿,急~~~~~~~~写了,给分的
|
#include
#include
int main()
{
char str[] = "S0101001_200809";
char front[16] = {0};
char rear[16] = {0};
char *p;
p = strtok(str, "_");
strcpy(front, p);
p = strtok(NULL, "_");
strcpy(rear, p);
printf("%sn", front);
printf("%sn", rear);
return 0;
}
#include
int main()
{
char str[] = "S0101001_200809";
char front[16] = {0};
char rear[16] = {0};
char *p;
p = strtok(str, "_");
strcpy(front, p);
p = strtok(NULL, "_");
strcpy(rear, p);
printf("%sn", front);
printf("%sn", rear);
return 0;
}
|
#include
#include
int main(void)
{
char string[16];
char start_time[16] = {0};
char kikai_num[16] = {0};
char *s, c = '_';
int scnt = 0;
int tcnt = 0;
strcpy( string, "S0101002_200812");
s = strrchr(string,'_');
scnt = strlen(s+1);
memcpy(kikai_num,string,s - string);
memcpy(start_time,s+1,scnt);
printf("kikai_num:%sn",kikai_num);
printf("start_time:%sn",start_time);
return 0;
}
#include
int main(void)
{
char string[16];
char start_time[16] = {0};
char kikai_num[16] = {0};
char *s, c = '_';
int scnt = 0;
int tcnt = 0;
strcpy( string, "S0101002_200812");
s = strrchr(string,'_');
scnt = strlen(s+1);
memcpy(kikai_num,string,s - string);
memcpy(start_time,s+1,scnt);
printf("kikai_num:%sn",kikai_num);
printf("start_time:%sn",start_time);
return 0;
}