• 7585阅读
  • 7回复

怎么解析一串QString字符 [复制链接]

上一主题 下一主题
离线succulent
 
只看楼主 倒序阅读 楼主  发表于: 2008-12-10
— 本帖被 XChinux 执行加亮操作(2008-12-11) —
比如QString var =“127.0.0.1&xxxxxxxx”
想单独把127.0.0.1解析出来赋给另一个变量
用什么方式比较好,有专门的API吗
如果自己编程实现,在QT下如何实现比较合适
离线guoyun_he

只看该作者 1楼 发表于: 2008-12-10
如果字符串都是你说的那种形式的话,你可以先找到第一个‘&’的位置,然后用left函数取出来就行了。
int QString::find ( const QString & str, int index=0, bool cs=TRUE ) const
Finds the first occurrence of the string str, starting at position index. If index is -1, the search starts at the last character; if -2, at the next to last character; etc.

The search is case sensitive if cs is TRUE, or case insensitive if cs is FALSE.

Returns the position of str, or -1 if str could not be found.

QString QString::left ( uint len ) const
Returns a substring that contains the len leftmost characters of the string.

The whole string is returned if len exceeds the length of the string.

Example:

    QString s = "Pineapple";
    QString t = s.left( 4 );    // t == "Pine"
离线succulent
只看该作者 2楼 发表于: 2008-12-10
哈,谢谢,很好的解释
离线lazybone
只看该作者 3楼 发表于: 2008-12-10
String s = "1254476@DFJSDFG";
s.substring(0, s.indexOf("@"));
离线uyoufaith

只看该作者 4楼 发表于: 2008-12-10
正则表达式
离线XChinux

只看该作者 5楼 发表于: 2008-12-11
var.section("&", 0, 0);
二笔 openSUSE Vim N9 BB10 XChinux@163.com 网易博客 腾讯微博
承接C++/Qt、Qt UI界面、PHP及预算报销系统开发业务
离线xjcook

只看该作者 6楼 发表于: 2008-12-11
我一般喜欢用split
离线mumutouv

只看该作者 7楼 发表于: 2008-12-11
support XCLinux
快速回复
限100 字节
 
上一个 下一个