简体   繁体   English

Qt C++中的字符串比较

[英]String comparison in Qt C++

User writes line in lineEdit and i should check if this line contains the following structure:用户在 lineEdit 中写入一行,我应该检查这一行是否包含以下结构:

"any characters other than commas", "any characters other than commas" “逗号以外的任何字符”,“逗号以外的任何字符”

and so on, for example:等等,例如:

qwe, asd, qwe, ertqsd

I did this by using many checks, but i want to compare this by one check.我通过使用许多支票来做到这一点,但我想通过一张支票进行比较。

This is my code and it checks many wrong positions for "," and " "这是我的代码,它会检查“,”和“”的许多错误位置

if(!checkSkillsComma)
    checkSkillsComma=tableSkills.contains(", ,", Qt::CaseInsensitive);

if(!checkSkillsComma)
    checkSkillsComma=tableSkills.contains(" ,", Qt::CaseInsensitive);

if(!checkSkillsComma)
    checkSkillsComma=tableSkills.contains("  ", Qt::CaseInsensitive);

if(!checkSkillsComma)
    checkSkillsComma=tableSkills.endsWith(",");

if(!checkSkillsComma)
    checkSkillsComma=tableSkills.endsWith(" ");

if(!checkSkillsComma)
    checkSkillsComma=tableSkills.startsWith(",");

if(!checkSkillsComma)
    checkSkillsComma=tableSkills.startsWith(" ");

It is better to use QRegularExpression if I understood the question correctly.如果我正确理解问题,最好使用 QRegularExpression。 Some trick is to use QString::split(",").一些技巧是使用 QString::split(",")。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM