QString用法

QString 字符串操作

QString str1 = "Welcom";
str1 = str1+" to New York!";
//str1 = "Welcom to New York!"

QString str2 = "Welcom";
str2 +=" to New York!";
//str2 = "Welcom to New York!"

QString str3 = "Welcom";
QString str4 = "to";
str3.append(str4);
str3.append(" New York!");
//str3 = "Welcom to New York!"

QString str5;
str5.sprintf("%s %s","Welcom to","New York!")
//str5 = "Welcom to New York!"

QString str6;
str6 = QString("%1 to %2!").arg("Welcom").arg("New York");
//str6 = "Welcom to New York!"

特定操作

QString::insert();//指定位置插入字符串
QString::prepend();//开头位置插入字符串
QString::replace();//用指定字符串 替换某字符串
QString::trimmed();//移除字符串两端空白    
QString::simplified();//移除字符串两端空白,使用单个空格代替字符中出现的空白字符

查询字符串数据

QString::statrsWith();//是否以某个字符串开头
QString::contains();//是否包含某个字符串
QString::endsWith();//是否已某个字符串结束

比较字符串

operator<(const QString&)	//是否小于 返回bool类型
operator<=(const QString&)	//是否小于等于 返回bool类型
operator==(const QString&)	//是否相等 返回bool类型
operator>=(const QString&)	//是否大于等于 返回bool类型

字符串转换、判断

QString::toInt();
QString::toDouble();
QString::toFloat();
QString::toLong();
QString::toLongLong();

QString::isNull();//判断是否为NULL字符串
QString::toEmpty();//判断是否为空字符串
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值