如何比较C ++中的字符串? [英] How to compare the string in C++?

查看:219
本文介绍了如何比较C ++中的字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

checkFormat(string &s)
{

}

string s是一个表示日期的字符串。

string s is a string that indicate the date.

我想比较一个字符串s,

I want to compare a string s, to find whether it is in terms of "yyyy:mm::dd" or not.

我应该怎么办?

compare它char by char?如果字符串是600:12:01怎么办?

compare it char by char? What if the string is "600:12:01" ?

对不起,我的英语不好。

Sorry for my poor English.

推荐答案

不要使用正则表达式。使用 strptime(),用于解析时间字符串(因此名称: str p time ,string - parse - > time)。正则表达式无法确定 2013:2:29 无效。

Don't use regex. Use strptime(), which is designed to parse time strings (hence the name: str p time, string -> parse -> time). A regex can't figure out that 2013:2:29 is invalid.

这篇关于如何比较C ++中的字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆