I have these url strings
file:///home/we/Pictures/neededWord/3193_n.jpg
file:///home/smes/Pictures/neededWord/jds_22.png
file:///home/seede/kkske/Pictures/neededWord/3193_n.jpg
I want to extract the "neededWord" from each of them. As it appears from them, the name of the image is always after the "neededWord" and the changing part in the string is before the "neededWord". The way I thought of is to split the string using the "/" seperator from right and take the second element in the resulted QstringList. So how to split from right, or is there a better way to do that?
QString stores unicode strings. By definition, since QString stores unicode, a QString knows what characters it's contents represent. This is in contrast to a C-style string (char*) that has no knowledge of encoding by itself.
One way to initialize a QString is simply to pass a const char * to its constructor. For example, the following code creates a QString of size 5 containing the data "Hello": QString str = "Hello"; QString converts the const char * data into Unicode using the fromAscii() function.
Try this: double d1 = 0.5,d2 = 30.0 QString str = "abc"; str. append(QString("%1"). arg(d1)); str.
Well you would just take the second to last element:
QStringList pieces = url.split( "/" ); QString neededWord = pieces.value( pieces.length() - 2 );
Alternatively, you could use a regular expression.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With