zoukankan      html  css  js  c++  java
  • QString组合、拆分。

    1、组合字符常用arg()函数

    QString  test=QString("_haha_%1_hehe%2") .arg("ee").arg("aa");      //test="_haha_ee_heheaa"
    
    eg:arg(const QString &a, int fieldWidth = 0, QChar fillChar = QLatin1Char( '  ' )) const        参数1.连接的字符;参数2.字符所占据的宽度;参数3.如果字符的宽度小于参数2的宽度,则用参数3的字符填充。

    如下图所示:fieldWidth >0 ,代表的右对齐;   fieldWidth <0,代表的左对齐。如下图所示:

      

    .

    2、提取具有分割符的字符串用section()函数

    QString QString::section(QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault) const    //参数1,代表分隔符;参数2,提取字符的起始位置;参数3,提取字符的结束位置。
    
    eg: 
    
    QString str;
    
    QString csv = "forename,middlename,surname,phone";
    
    QString path = "/usr/local/bin/myapp"; // First field is empty
    
    QString::SectionFlag flag = QString::SectionSkipEmpty;    //Treat empty fields as if they don't exist, i.e. they are not considered as far as start and end are concerned.
    
    str = csv.section(',', 2, 2); // str == "surname"。("forename,middlename,surname,phone")
    
    str = path.section('/', 3, 4); // str == "bin/myapp"。("/usr/local/bin/myapp")
    
    str = path.section('/', 3, 3, flag); // str == "myapp"  ("/usr/local/bin/myapp")空字符串开始的地方不被当做开始或结束的地方
    

    3、QString在结构体中是直接当做4个字节的指针来占用内存的

    坚持成就伟大
  • 相关阅读:
    PHP中使用CURL实现GET和POST请求
    ecstore关于smarty语法调用
    Linux 定时任务详解
    fzu 1753 Another Easy Problem
    zoj 2562 More Divisors
    poj 2992 Divisors
    UVA10078多边形判断凹凸性
    UVA10002求凸包的质心
    UVA10088多边形内整点个数计算(计算几何)
    HDU 1824 简单2-sat
  • 原文地址:https://www.cnblogs.com/xian-yongchao/p/9482746.html
Copyright © 2011-2022 走看看