QString の一般的なメソッド

index at; インデックス i の文字を返すか、i が文字列の長さを超える場合は 0 を返します

const QString string( "abcdefgh" );
QChar ch = string.at( 4 );
	   

QString toLower() //小文字に変換
QString toUpper() //大文字に変換

QString c("cle");
QString str=c.toUpper();   // str == "cle"
qDebug()<<str;

末尾挿入追加; push_back

ヘッド挿入プリペンド; push_front

QString cer = "data";
cer.append("list");
cer.push_back("yes");
cer.prepend("like");
cer.push_front("good");
qDebug()<<cer;

基本型変換

s1.toUInt();
s1.toDouble();
s1.toFloat();
s1.toShort();
s1.toLong();
s1.toULongLong();

長さ

s1.size()
s1.count();
s1.length();

文字列がゼロの場合は true を返します。ゼロ文字列は常に空です。

 QString a;          // a.unicode() == 0,a.length() == 0
 a.isNull();         // 真,因为a.unicode() == 0
 a.isEmpty();        // 真
比較
 int a = QString::compare( "def", "abc" );   // a > 0
 int b = QString::compare( "abc", "def" );   // b < 0
 int c = QString::compare(" abc", "abc" );   // c == 0

文字列の途中の文字を削除する

QString str = "Hello World!";
str.remove(5, 6);                   // str = "Hello!"

指定位置に文字を挿入

QString str = "Hello!";
str.insert(5, QString(" World"));   // str = "Hello World!"

QString::number 整数変換

int a = 20;
uint b =255;
QString::number(a);
QString::number(a,10);
QString::number(b);
QString::number(b,16);

上記は QString で一般的に使用される簡単な例です; より多くの例が探求されるのを待っています!

おすすめ

転載: blog.csdn.net/qq_55365635/article/details/128702534