#include <QCoreApplication>//qt提供的事件循环
#include <QDebug>//输出流
#include <QString>
#include <iostream>
#include <QDateTime>
using namespace std;
int main()
{
// QCoreApplication a(argc, argv);
// //1:QString 提供"+"操作符应用,功能一样"+="
// QString str1 ="Ling";
// str1 = str1 + "sheng EDU";
// qDebug()<< str1;//打印信息
// qDebug()<< qPrintable(str1);//去掉双引号
// //qPrintable(str1);去掉双引号
// //2:QString 提供"+="操作符应用
// QString str2 ="123545";
// str2 +="ABCDE";
// qDebug()<< str1;//打印信息
// qDebug()<< qPrintable(str2);//去掉双引号
// //3:QString::append()函数
// QString str3 ="Good";
// QString str4 ="bye";
// str3.append(str4);
// qDebug()<< qPrintable(str3);//去掉双引号
// str3.append(" hello world !");
// qDebug()<< qPrintable(str3);//去掉双引号
// //3组合字符串QString::arg()函数
// QString strtemp,strtemp1;
// strtemp = QString("value:%1").arg("hello");
// qDebug()<< qPrintable(strtemp);//去掉双引号
// strtemp1 = QString("value:%1,%1").arg("hello").arg(" world");
// qDebug()<< qPrintable(strtemp1);//去掉双引号
// return a.exec();//应用程序返回的时候会执行
/*
* 4组合字符串QString::startWith()函数,判断一个字符串是否以某个字符
* 出现过
*/
// QString strTemp2 = "How are you";
// qDebug()<< strTemp2.startsWith("How",Qt::CaseInsensitive);//true
// qDebug()<< strTemp2.startsWith("are",Qt::CaseInsensitive);//false
// //5.contains()函数判断一个指定的字符串是否出现过
// qDebug()<< strTemp2.contains("Hows",Qt::CaseInsensitive);//false
// //6.QStriing::toInt()将字符串转换为整数数值
// QString str = "25";
// bool isloop;
// int hex = str.toInt(&isloop,16);
// qDebug()<<"isloop="<<isloop<<","<<"hex="<< hex;
// //6.QStriing::compare()函数
// //大小写不敏感
// int a1 = QString::compare("abcd","ABCD",Qt::CaseInsensitive);
// //大小写敏感
// int b2 = QString::compare("about","Cat",Qt::CaseSensitive);
// int c3 = QString::compare("abcd","Cat",Qt::CaseInsensitive);
// cout<<"a1 "<< a1<<" b2 "<< b2 << " c3 "<< c3 << endl;
//8.Qt将QStrin转换成对应ASCLL码
// QString str1 = "ABC abc";
// QByteArray bytes = str1.toUtf8();
// for(int i=0;i<str1.size();i++)
// {
// qDebug()<<int(bytes.at(i));
// }
//9:QDateTime QByteArray
QDateTime dt;
QString strDT = dt.currentDateTime().toString("yyyy-MM-dd hh:mm:ss");
qDebug()<<strDT;
QByteArray a1("Qt Create Hello world");
QByteArray b1 = a1.toLower();//将字符串大写字母转小写, 小写不变
qDebug()<<b1 ;
QByteArray c1 = a1.toUpper();//将字符串大写字母转小写, 小写不变
qDebug()<<c1 ;
}
41-字符串类应用与常用数据类型
于 2024-05-08 22:12:34 首次发布