操作字符串
2016-06-07 13:53
246 查看
//组合两个字符串“+”,“+=” QString str1="Welcome"; str1=str1+"to you!"; //str1="Welcome to you!" QString str2="Hello, "; str2+="World!"; //str2="Hello,World!" //QString::append()追加字符串 QString str1="Welcome "; QString strw="to"; str1.append(str2); //str1="Welcome to" str1.append("you!"); //str1="Welcome to you!" //QString::sprintf()输出字符串 QString str; str.sprintf("%s","Welcome"); //str="Welcome" str.sprintf("%s","to you!"); //str="to you!" str.sprintf("%s","Welcome","to you!") //str="Welcome to you! //QString::arg()函数,功能更强: //支持多数据类型、 //设置字段宽度 //数字基数 //浮点数精度 QString str; str=QString("%1 was born in %2.").arg("John").arg(1992);//str="John was born in 1992." insert()函数:在原字符串特定的位置插入另一个字符串 prepend()函数:在原定字符串开头的位置插入另一个字符串 replase()函数:用指定的字符串代替原字符串中的某些字符 QString::trimmed():移除字符串两端的空白字符 QString::simplified():移除字符串两端的空白字符,使用单个空格字符“ ”代替字符串中出现的空白字符 *空白字符包括回车"\n",换行字符"\r",制表符"\t"和空格字符" "等 QString str="Welcome \t to \n you! "; str=str.trimmed(); //str="Welcome \t to \n you!"
相关文章推荐
- python语法------时间函数
- 导航栏透明渐变(iOS)
- CSS3自定义@font-face
- iOS开发之遍历Model类的属性并赋值
- java程序想mysql数据库插入数据乱码解决方法()
- Wet Shark and Odd and Even
- 地理数据库需要什么类型的维护?
- android开发(48) Android Snackbar 的使用
- qt序列化 (二)
- java中正则表达式的使用(2)——列出百度搜索的前十项
- linux内核研究(一)
- jQuery中attr和prop的区别
- 冒泡、快速以及插入排序算法
- 听云配置探针
- iOS开发拓展篇—音频处理(音乐播放器3)
- odoo 销售订单出库单操作代码简单剖析
- Ajax基础教程
- clang编译器简介
- Android_指引点View
- C# Winform中的DataGridView中行定位-滚动条定位