字符串中提取年月日,year、month、day,格式:year=2012,month=march-April、day=6-8string date("Jan.30 2012-Feb.2 2012");string date("Jan.30-Feb.2 2012");string date("30 March-3 April 2003");string date("6-8 May 2012");string date("12 April

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/11 18:41:32
字符串中提取年月日,year、month、day,格式:year=2012,month=march-April、day=6-8string date(

字符串中提取年月日,year、month、day,格式:year=2012,month=march-April、day=6-8string date("Jan.30 2012-Feb.2 2012");string date("Jan.30-Feb.2 2012");string date("30 March-3 April 2003");string date("6-8 May 2012");string date("12 April
字符串中提取年月日,year、month、day,格式:year=2012,month=march-April、day=6-8
string date("Jan.30 2012-Feb.2 2012");
string date("Jan.30-Feb.2 2012");
string date("30 March-3 April 2003");
string date("6-8 May 2012");
string date("12 April 2012");
string date("Nov/Dec.12 2012");
string date("April 12 2012");
string date("April 2012");
string date("2012");

字符串中提取年月日,year、month、day,格式:year=2012,month=march-April、day=6-8string date("Jan.30 2012-Feb.2 2012");string date("Jan.30-Feb.2 2012");string date("30 March-3 April 2003");string date("6-8 May 2012");string date("12 April
比较繁.
先找有无 - 或 /, 有则分为2 个部分,无, 则是 1个部分.
然后 把两部分 的 字符串 抓出来.
字符串判断,字母开始 是 月,其它,4个数字是年,余下是 日.
用C++找 - 或 / :
size_t pos=0; pos = str.find("-");
if (pos==0) pos = str.find("/");

用C:
string str("Jan. 30 2012-Feb. 2 2012");
int main ()
{
int i;
int found= -1;
char s1[3][10],s2[3][10];
int n1=0,n2=0;
char cstr[40],c1[40],c2[40];

strcpy (cstr, str.c_str());
for (i=0;i < str.length(); i++) if ( cstr[i]=='-' || cstr[i]=='/') {
found = i; cstr[i]=' ';
}
if (found > 0) {
strcpy(c1,cstr); c1[found]='\0';
n1 = sscanf(c1,"%s %s %s",s1[0],s1[1],s1[2]);
strcpy(c2, &cstr[found+1]);
n2 = sscanf(c2,"%s %s %s",s2[0],s2[1],s2[2]);
} else{
n1 = sscanf(cstr,"%s %s %s",s1[0],s1[1],s1[2]);
}
前1 部分 的 字符串 在 s1[0],s1[1],s1[2] 中,年月日个数为 n1
后1 部分 的 字符串 在 s2[0],s2[1],s2[2] 中, 年月日个数为 n2
然后循环判断一下即可
取出的字符串是否正确,可以临时打印出来看:
for (i=0;i

字符串中提取年月日,year、month、day,格式:year=2012,month=march-April、day=6-8string date(Jan.30 2012-Feb.2 2012);string date(Jan.30-Feb.2 2012);string date(30 March-3 April 2003);string date(6-8 May 2012);string date(12 April 如何从身份证号码中提取出生年月日? 4.设int year,month,day分别表示一个日期中的年月日,试编程求 C语言程序设计:写一个函数,从给定的身份证号中提取出生年月日 C++编写一个week函数,其功能是根据表示年月日的三个整型变量year,month和day,返回星期几的值 . 这个是已经1900年1月1日星期一 然后输入年月日 算出 输入的这个年,月,日是星期几#includevoid main(){int year,month,day;int sum=0,i,week,num,leap;printf(请输入年月日 );scanf(%d%d%d,&year,&month,&day);for(i=1900;i 关于matlab中date()函数的一道题MATLAB 的date()函数可以返回当前年月日信息.试写出一个函数,利用date()函数获取日期信息后,按如下要求返回当前的year、month、day(a) 总是能返回 day;(b) 如果调用该 ( )month( )Day( )Year month/year 05/19 c语言,已知1年1月1日是星期一,计算输入的年月日是星期几#includevoid main(){ int year,month,day,sum,i,xingqi; printf(请输入年 月 日:); scanf(%d %d %d,&year,&month,&day); switch(month) { case 1:sum= 用函数计算每个月的天数,C语言问题,必须是先设计一个函数我这个哪里错了?#include #includeint main(void){ int f(int x,int y);int year ,month,day,t;printf(输入年月日:);scanf(%d%d%d,&year,&month,&day);t==f(year,mon 英语中年月日的表达方式 英语中年月日的读法 年月日这种记时单位是中国发明的吗?年 year 月month 天day.这记时单位是古代中国传给外国的?还是自古共有的吗? 表格中年月日减年月日时什么函数公式? EXCEL 用MONTH () 提取单元格中的月份,为什么空白表格中会返回1? 亲,帮小女子看看这个c语言程序 改错改错 输出该日为该年的第几天 #includevoid main(){int jisuanday,y1,y2,year,month,day;int panduan1(int month);int panduan2(int year);printf(请输入任意年月日,逗号隔开.);scanf(%d, 英语 写出句中所缺的单词1、The first month of the year is( )2、The last month of the year is ( )3、The ( )month of the year is October.4、September is the ( )month of the year.5、The sixth month of the year is (