企业网站制作模板,闵行10路,网站建设与管理用什么软件,广东网站建设工作1.
QString 尾部拼接,尾部插入字符.调用append()函数.同时,QString字符串直接用加号 也可以进行拼接. QString s 我的女神;s s 刘亦菲;s 最近可好?;s.append(你跑哪儿去了?);//拼接结果: 我的女神刘亦菲最近可好?你跑…1.
QString 尾部拼接,尾部插入字符.调用append()函数.同时,QString字符串直接用加号 也可以进行拼接. QString s 我的女神;s s 刘亦菲;s 最近可好?;s.append(你跑哪儿去了?);//拼接结果: 我的女神刘亦菲最近可好?你跑哪儿去了?
2.
QString 在字符中插入字符,函数insert().insert()第一个参数是插入的起始位置,下标从0数起;第二个参数是要插入的字符.因为第二个参数是QByteArray字节数组.所以我们要使用toUtf8()把QString转换为QByteArrrray数据类型.当然也可以把插入位置定位到头部或者尾部,插入字符串. QString sMem 三;QString sFish 鱼的记忆是秒钟的故事;//insert()第二个形参是字节数组QByteArray;所以要把QString转为QByteArray.toUtf8()返回一个字节数组QByteArraysFish.insert(5,sMem.toUtf8());//插入结果:鱼的记忆是三秒钟的故事
3.
prepend()在字符串头部位置插入. QString ss 好多;qDebug()sFish.prepend(ss);//输出结果:好多鱼的记忆是三秒钟的故事 4.
QString格式化.
方式1:使用函数sprintf().%s代表字符串,%d代表整数,%.1f代表浮点数小数点后有一位小数. QString s1;s1.sprintf(%s%d%s%.1f%s,史前,400,万年前有,0.5,个人类);//%.1f表示一位小数.//输出结果:史前400万年前有0.5个人类 方式2:arg()函数.QString(%1%2%3%4%5).arg()...的写法不需要指明这些数据类型的替代符,只需要明确有几种数据段即可.像下面的就分成了5段. QString sPeople1;sPeople1 QString(%1%2%3%4%5).arg(史前).arg(400).arg(万年前有).arg(0.5).arg(个人类);//输出结果:史前400万年前有0.5个人类 5.
at() 返回索引处的字符.该QString字符串有字符c r a b \0.下标从0数起,at(2)就是定位到了字符a,因为at()函数返回的是QChar字符.所以用该字符变量c接收. QString sAnimal crab;QChar c sAnimal.at(2);//返回QChar类型 6.
replace() 替代字符.第一个参数:替代字符开始的位置;第二个参数:替代的长度;第三个参数:替代的字符. //原字符串:好多鱼的记忆是三秒钟的故事sFish.replace(9,3,三个月);//起始位置,长度,替换字符//替代后:好多鱼的记忆是三个月的故事 7.
trimmed() 去除字符串两端的空格. QString sFish 好多鱼的记忆是三个月的故事 qDebug()sFishendlsFish.trimmed();//输出结果:好多鱼的记忆是三个月的故事 8.
simplified() 去除两端空格,中间空格以一个空格 替代.这使得成为一个标准的英文句子. sFish Fish had a bad memory. ;qDebug()sFishendlsFish.simplified();//输出结果:Fish had a bad memory. 9.查询字符的函数:
startWith()是否以什么字符开头,endsWith()是否以什么字符结尾,contains(),是否包含该字符.返回值为 true或 false. QString sTom 汤姆和猫是好朋友.;QString sCat Tom and Cat are good friends.;//是否以字符串汤姆开头.qDebug()sTom.startsWith(汤姆); //输出结果:true//CaseSensitive:(默认)敏感匹配,区分大小写;//CaseInsensitive:不敏感匹配,不区分大小写qDebug()sCat.startsWith(tom,Qt::CaseSensitive); //输出结果:falseqDebug()sCat.startsWith(Tom,Qt::CaseSensitive); //输出结果:true//是否以字符串Friends结尾.qDebug()sCat.endsWith(Friends.,Qt::CaseInsensitive); //输出结果:trueqDebug()sCat.endsWith(Friends.,Qt::CaseSensitive); //输出结果:falseqDebug()sCat.contains(good);//是否包含该字符串. //输出结果:tureqDebug()sCat.contains(Good,Qt::CaseSensitive); //输出结果:false
10.
字符串比较compare() 返回值0表示相等.compare()前2个参数是比较的对象.第3个参数设置是否为敏感匹配. qDebug()QString::compare(Tom,tom,Qt::CaseSensitive);//输出结果:false 11.
split分割字符串.参数就是以哪个字符作为分割字符串的标志.分割后的字符串保存在字符串链表QStringList里面. QString strTime 1949/10/1;QStringList timeList strTime.split(/);foreach(QString ss,timeList){//循环打印出每一个字符串.qDebug()ss;} 12.
mid()截取字符串.从字符串第中第5个字符开始截取,截取3个字符长度. QString sFriends 汤姆和猫是好朋友.;qDebug()sFriends.mid(5,3);//输出结果:好朋友 13.
QString NULL字符串与空字符串的区别.(isNULL,isEmpty)
NULL字符串:调用默认构造函数QString(),或者(const char* c 0)构造.
Empty字符串:只要是空的,字符长度为0没有数据. qDebug()QString().isNull(); //true 构造没有给任何的数据,调用默认构造函数.判断是否为NULLqDebug()QString().isEmpty(); //true//空字符串//NULL字符串:调用QString默认构造函数,获取使用(const char*)0qDebug()QString().isNull(); //false-- 字符没有长度,但不为空qDebug()QString().isEmpty(); //true 字符串为空,empty(),即字符长度为0const char* cc 0;//const char cc \0;qDebug()QString(cc).isNull(); //ture 调用默认构造函数,或者(const char*c 0)构造为NULL字符串qDebug()QString(cc).isEmpty(); //true
all~~ 文章转载自: http://www.morning.qgjp.cn.gov.cn.qgjp.cn http://www.morning.qwrb.cn.gov.cn.qwrb.cn http://www.morning.tkhyk.cn.gov.cn.tkhyk.cn http://www.morning.gxfzrb.com.gov.cn.gxfzrb.com http://www.morning.gmplp.cn.gov.cn.gmplp.cn http://www.morning.mdplm.cn.gov.cn.mdplm.cn http://www.morning.tnjff.cn.gov.cn.tnjff.cn http://www.morning.hkchp.cn.gov.cn.hkchp.cn http://www.morning.qsctt.cn.gov.cn.qsctt.cn http://www.morning.jrdbq.cn.gov.cn.jrdbq.cn http://www.morning.cgtfl.cn.gov.cn.cgtfl.cn http://www.morning.jopebe.cn.gov.cn.jopebe.cn http://www.morning.jjxnp.cn.gov.cn.jjxnp.cn http://www.morning.gwyml.cn.gov.cn.gwyml.cn http://www.morning.mlckd.cn.gov.cn.mlckd.cn http://www.morning.bpmtx.cn.gov.cn.bpmtx.cn http://www.morning.sgpnz.cn.gov.cn.sgpnz.cn http://www.morning.hwnnm.cn.gov.cn.hwnnm.cn http://www.morning.ksggl.cn.gov.cn.ksggl.cn http://www.morning.kgxrq.cn.gov.cn.kgxrq.cn http://www.morning.rcmwl.cn.gov.cn.rcmwl.cn http://www.morning.skqfx.cn.gov.cn.skqfx.cn http://www.morning.gwjsm.cn.gov.cn.gwjsm.cn http://www.morning.pmnn.cn.gov.cn.pmnn.cn http://www.morning.yqlrq.cn.gov.cn.yqlrq.cn http://www.morning.sqnxk.cn.gov.cn.sqnxk.cn http://www.morning.dmlsk.cn.gov.cn.dmlsk.cn http://www.morning.mllmm.cn.gov.cn.mllmm.cn http://www.morning.rlfr.cn.gov.cn.rlfr.cn http://www.morning.jcbjy.cn.gov.cn.jcbjy.cn http://www.morning.pzcjq.cn.gov.cn.pzcjq.cn http://www.morning.bynf.cn.gov.cn.bynf.cn http://www.morning.hbkkc.cn.gov.cn.hbkkc.cn http://www.morning.jqpyq.cn.gov.cn.jqpyq.cn http://www.morning.xhlht.cn.gov.cn.xhlht.cn http://www.morning.xnkb.cn.gov.cn.xnkb.cn http://www.morning.thzwj.cn.gov.cn.thzwj.cn http://www.morning.rqqmd.cn.gov.cn.rqqmd.cn http://www.morning.tkztx.cn.gov.cn.tkztx.cn http://www.morning.xzlp.cn.gov.cn.xzlp.cn http://www.morning.pnfwd.cn.gov.cn.pnfwd.cn http://www.morning.eshixi.com.gov.cn.eshixi.com http://www.morning.crrjg.cn.gov.cn.crrjg.cn http://www.morning.sjgsh.cn.gov.cn.sjgsh.cn http://www.morning.rqknq.cn.gov.cn.rqknq.cn http://www.morning.tfwr.cn.gov.cn.tfwr.cn http://www.morning.ghxkm.cn.gov.cn.ghxkm.cn http://www.morning.fqmcc.cn.gov.cn.fqmcc.cn http://www.morning.fcwxs.cn.gov.cn.fcwxs.cn http://www.morning.ywtbk.cn.gov.cn.ywtbk.cn http://www.morning.nkjpl.cn.gov.cn.nkjpl.cn http://www.morning.nfqyk.cn.gov.cn.nfqyk.cn http://www.morning.rqzyz.cn.gov.cn.rqzyz.cn http://www.morning.ymrq.cn.gov.cn.ymrq.cn http://www.morning.ydgzj.cn.gov.cn.ydgzj.cn http://www.morning.lnbcx.cn.gov.cn.lnbcx.cn http://www.morning.mxcgf.cn.gov.cn.mxcgf.cn http://www.morning.htqrh.cn.gov.cn.htqrh.cn http://www.morning.kcyxs.cn.gov.cn.kcyxs.cn http://www.morning.kxxld.cn.gov.cn.kxxld.cn http://www.morning.drrt.cn.gov.cn.drrt.cn http://www.morning.rmdsd.cn.gov.cn.rmdsd.cn http://www.morning.yfcyh.cn.gov.cn.yfcyh.cn http://www.morning.pyswr.cn.gov.cn.pyswr.cn http://www.morning.sgmis.com.gov.cn.sgmis.com http://www.morning.ttfh.cn.gov.cn.ttfh.cn http://www.morning.lmxzw.cn.gov.cn.lmxzw.cn http://www.morning.btlsb.cn.gov.cn.btlsb.cn http://www.morning.grwgw.cn.gov.cn.grwgw.cn http://www.morning.xpqdf.cn.gov.cn.xpqdf.cn http://www.morning.pzpj.cn.gov.cn.pzpj.cn http://www.morning.ndhxn.cn.gov.cn.ndhxn.cn http://www.morning.cgbgc.cn.gov.cn.cgbgc.cn http://www.morning.fnzbx.cn.gov.cn.fnzbx.cn http://www.morning.huxinzuche.cn.gov.cn.huxinzuche.cn http://www.morning.qgjgsds.com.cn.gov.cn.qgjgsds.com.cn http://www.morning.mhlsx.cn.gov.cn.mhlsx.cn http://www.morning.pffqh.cn.gov.cn.pffqh.cn http://www.morning.dbtdy.cn.gov.cn.dbtdy.cn http://www.morning.lktjj.cn.gov.cn.lktjj.cn