Results 1 to 2 of 2

Thread: index of a string that appears n times

  1. #1
    Join Date
    Aug 2017
    Posts
    8
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Windows

    Post index of a string that appears n times

    hello i am able to get index of "@" in c++ but not in qt. i dont know what i have to use to find("@",found+1,q)
    Qt Code:
    1. #include <iostream> // std::cout
    2. #include <string> // std::string
    3.  
    4. int main ()
    5. {
    6. std::string str ("msel@-txt/l<seq_name>@#ifndef I_MSEL_@-txt/u<seq_name>@_H");
    7. std::string tag ("@");
    8.  
    9.  
    10.  
    11. // different member versions of find in the same order as above:
    12. std::size_t found = str.find(tag);
    13. if (found!=std::string::npos)
    14. std::cout << "first '@' found at: " << found << '\n';
    15.  
    16. for (int i = 0; i <= 5; i++)
    17. { int q =1;
    18. found=str.find("@",found+1,q);
    19. q++;
    20. if (found!=std::string::npos)
    21. std::cout << " '@' found at: " << found << '\n';
    22. }
    23.  
    24. return 0;
    25. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: index of a string that appears n times

    but not in qt
    Show the Qt code.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    deepikha (23rd October 2017)

Similar Threads

  1. Nested loop only loops 3 times instead of 710 times
    By ayanda83 in forum Qt Programming
    Replies: 1
    Last Post: 18th October 2016, 19:12
  2. Replies: 2
    Last Post: 4th February 2014, 12:47
  3. PyQT Listview index to string
    By Dariusz in forum Newbie
    Replies: 1
    Last Post: 28th September 2013, 10:05
  4. Nothing appears in QScrollArea
    By space_otter in forum Qt Programming
    Replies: 1
    Last Post: 16th November 2011, 14:28
  5.  appears in QTextBrowser
    By szisziszilvi in forum Qt Programming
    Replies: 1
    Last Post: 4th March 2011, 09:21

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.