startsWith() 是 QString 类中的一个成员函数,用于检查字符串是否以指定的前缀开头

startsWith()QString 类中的一个成员函数,用于检查字符串是否以指定的前缀开头。

以下是 startsWith() 函数的常见用法:

QString str = "Hello, World!";
bool startsWith = str.startsWith("Hello");  // 返回 true

QString prefix = "He";
bool startsWithPrefix = str.startsWith(prefix);  // 返回 true

在这个示例中,我们有一个字符串 str,内容为 “Hello, World!”。通过调用 startsWith() 函数并传递一个参数作为前缀,可以检查字符串是否以该前缀开头。

如果字符串以指定的前缀开头,则 startsWith() 函数返回 true;否则,返回 false

需要注意的是,startsWith() 函数默认情况下是区分大小写的。如果你希望进行不区分大小写的比较,可以使用 startsWith() 函数的重载形式,并传递 Qt::CaseInsensitive 作为第二个参数。

猜你喜欢

转载自blog.csdn.net/m0_46376834/article/details/134910240