Select a substring in QString
-
wrote on 30 Jun 2020, 15:39 last edited by
I have a string like "//Machine/C://DriveOne/File1". I wanted to select this part "DriveOne/File1" from that string. How can I do that? I have defined these strings a QString.
-
I have a string like "//Machine/C://DriveOne/File1". I wanted to select this part "DriveOne/File1" from that string. How can I do that? I have defined these strings a QString.
wrote on 30 Jun 2020, 15:45 last edited by@Azadshahr
Before anyone answers this, are you sure about theC://
bit? Sure it isn't://Machine/C:/DriveOne/File1"
?
-
wrote on 30 Jun 2020, 16:01 last edited by
Yeah. It is "//Machine/C:/DriveOne/File1" correct. Sorry. However, I wanted to select "DriveOne/File1".
-
Simply split the string at "//" maybe?
-
Yeah. It is "//Machine/C:/DriveOne/File1" correct. Sorry. However, I wanted to select "DriveOne/File1".
wrote on 30 Jun 2020, 16:17 last edited by JonB@Azadshahr
I suspected so :) I asked because now looking for//
isn't going to help you.So you can either split at/index from
:/
, or useQRegularExpression
depending on just what you want to allow for. -
@JonB said in Select a substring in QString:
I asked because now looking for // isn't going to help you.
Why not? Simply split, take the last one.
-
@JonB said in Select a substring in QString:
I asked because now looking for // isn't going to help you.
Why not? Simply split, take the last one.
wrote on 30 Jun 2020, 17:31 last edited by JonB@Christian-Ehrlicher
Have you seen that the OP confirmed the string is://Machine/C:/DriveOne/File1
Not as originally posted; there is no longer
//
in the middle. And he wants back:DriveOne/File1
Which is why I said split on
:/
. -
@Christian-Ehrlicher
Have you seen that the OP confirmed the string is://Machine/C:/DriveOne/File1
Not as originally posted; there is no longer
//
in the middle. And he wants back:DriveOne/File1
Which is why I said split on
:/
.@JonB Ah, sorry - but the logic is the same :)
1/8