QString split

Alles rund um die Programmierung mit Qt
Antworten
anno1988
Beiträge: 280
Registriert: 23. Januar 2009 20:49

QString split

Beitrag von anno1988 »

Hallo,

weiß jemand wie ich einen String in genau 2 Teile splitten kann?

Bsp:

Ich will folgenden String splitten: "123456:1233456:123456".

Er soll aber so gesplittet werden, dass nur beim ersten gefundenen Doppelpunkt in 2 Teile gespittet wird und nicht bei jedem Doppelpunkt (mit .split() habe ich es schon versucht, hat aber nicht funktioniert).
franzf
Beiträge: 3114
Registriert: 31. Mai 2006 11:15

Beitrag von franzf »

Der einfachst Weg: QString::indexOf(QChar) nehmen, Position des ersten ":" ermittteln und mit left() und right() die Substrings holen.
padreigh
Beiträge: 340
Registriert: 13. Mai 2010 10:06

Beitrag von padreigh »

API lesen .. das bildet:

http://doc.qt.nokia.com/stable/qstring.html

Code: Alles auswählen

QString 	section ( QChar sep, int start, int end = -1, SectionFlags flags = SectionDefault ) const
QString 	section ( const QString & sep, int start, int end = -1, SectionFlags flags = SectionDefault ) const
QString 	section ( const QRegExp & reg, int start, int end = -1, SectionFlags flags = SectionDefault ) const
Die helfen dir weiter ... versuchs mit 2,-1

ausserdem gibts noch mid zu denen die franzf schon nannte ...
Patrick (QtCreator 1.3.1, Qt 4.6.3)
---
template = subdirs
Antworten