Farzan Njr
Farzan Njr

Reputation: 51

Removing everything after specific character

I'm developing a Qt application. I have some Strings like :

(Sub String before @)

[email protected]

[email protected]

I want to use

43243263

325754754

How to do that?

Upvotes: 3

Views: 5140

Answers (2)

frogatto
frogatto

Reputation: 29285

You can use QString::indexOf and QString::mid methods to extract the desired part.

QString str = "[email protected]";
QString desired = str.mid(0, str.indexOf("@"));

Upvotes: 7

demonplus
demonplus

Reputation: 5821

I will assume you have QString.

QStringList partsList = yourString.split('@');

// your check here the length of list is 2

Your desired output QString will be at:

partsList.at(0)

Upvotes: 1

Related Questions