Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qstring Problem
Forum Update on Tuesday, May 27th 2025

Qstring Problem

Scheduled Pinned Locked Moved General and Desktop
5 Posts 5 Posters 1.7k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maybnxtseasn
    wrote on 18 Mar 2012, 03:28 last edited by
    #1

    Say i have a Qstring of the following

    QString str1 = "HelloWorldThere";

    How would i go about extracting the characters from index 2 all the way to index 7 within the string so i can effectively retrieve this sing.

    Qstring extractedString = "lloWor";

    Pretty much i just want to extract a string from within a string when i have a starting index and an ending index. Any help is greatly appreciated

    1 Reply Last reply
    0
    • P Offline
      P Offline
      poporacer
      wrote on 18 Mar 2012, 03:41 last edited by
      #2

      QString y = str1.mid(1, 6);

      1 Reply Last reply
      0
      • M Offline
        M Offline
        msx_br
        wrote on 18 Mar 2012, 03:44 last edited by
        #3

        I think QRegExp class can help you:

        "QRegExp Class Reference":http://qt-project.org/doc/qt-4.8/qregexp.html

        msx_br - Brazil (Netherlands)

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on 18 Mar 2012, 19:14 last edited by
          #4

          QRegExp is worthless for this situation. Please try not to confuse users with random answers that are vaguely related. poporacer suggests the right approach.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on 18 Mar 2012, 19:19 last edited by
            #5

            [quote author="poporacer" date="1332042095"] QString y = str1.mid(1, 6);[/quote]
            This is the right approach, but it should be:
            @ QString y = str1.mid(2, 6);@

            Vote the answer(s) that helped you to solve your issue(s)

            1 Reply Last reply
            0

            1/5

            18 Mar 2012, 03:28

            • Login

            • Login or register to search.
            1 out of 5
            • First post
              1/5
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved