Qt学习——字符串类QString

 
  1. 操作字符串:
  • “+”操作: 
    view plain copy to clipboard print ?
    1. QString str1="25";   
    2. QString str2="You are ";  
    3.  str2+=str1+"!";  
    QString str1="25"; QString str2="You are "; str2+=str1+"!";
  • append()函数:相当于“+=”
    view plain copy to clipboard print ?
    1. QString str1="25";  
    2. QString str2="You are ";   
    3. str2.append(str1);  
    QString str1="25"; QString str2="You are "; str2.append(str1);
  • sprintf()函数:
    view plain copy to clipboard print ?
    1. QString str;  
    2. str.sprintf("%s","hello");  
    QString str; str.sprintf("%s","hello");
  • arg()函数:
    view plain copy to clipboard print ?
    1. QString str;  
    2. str=QString("%1 is a %2").arg("liming").arg("boy");  
    QString str; str=QString("%1 is a %2").arg("liming").arg("boy");

  • trimmed()函数去除字符串两端空白字符
    view plain copy to clipboard print ?
    1. QString str="    Zhao Liming   ";  
    2. str.trimmed();  
    QString str=" Zhao Liming "; str.trimmed();
 2.查询字符串:
  • startsWith()函数:
    view plain copy to clipboard print ?
    1. QString str="Hello World";  
    2. str.startsWith("Welcome",Qt::CaseSensitive);//返回true  
    QString str="Hello World"; str.startsWith("Welcome",Qt::CaseSensitive);//返回true
  • contains()函数:
    view plain copy to clipboard print ?
    1. str.contains("Welcome",Qt::CaseSensitive);//返回true  
    str.contains("Welcome",Qt::CaseSensitive);//返回true
  • <,<=,==,>=等操作符
 3. 字符串转换:
  • toInt()函数转换字符串到int类型: 
    view plain copy to clipboard print ?
    1. QString str1="25"bool ok;  
    2. int hex=str1.toInt(&ok,16);//ok返回是否转换成功,转换为16进制,默认为10进制  
    QString str1="25"; bool ok; int hex=str1.toInt(&ok,16);//ok返回是否转换成功,转换为16进制,默认为10进制
  • toDouble(),toAscii(),toUtf8()等。
Qt学习——字符串类QString_第1张图片
http://blog.csdn.net/a649518776/article/details/6630964

你可能感兴趣的:(qt,hex)