Thread: string question?? help?

  1. #1
    Registered User
    Join Date
    Jun 2002

    string question?? help?


    I'm fairly new to C++ and am having some trouble and would appreciate any help. I have a string ex: "ATCTCAGCGTACCGTA". I want to be able to find all the positions that have "GTA", there's one at position 8 (counting from 0) and at 13, however whenever I use the find function included in the string library, it will only give me the place where the first such string is found, in this example being 8.
    Is there any way I can use some other function or another way I can do this so that it will give me both the number 8 and 13, ad they are the places where "GTA" occurs. Any help will be greatly appreciated.. thanks

  2. #2
    Confused Magos's Avatar
    Join Date
    Sep 2001
    void PrintLocations(char* FullString, char* SubString)
       int Position = 0;
       int SubPosition;
       bool Failed;
       cout << "String: " << FullString << endl;
       cout << "SubString: " << SubString << endl;
       cout << "Matching positions: ";
       while(Position < strlen(FullString))
          SubPosition = 0;
          Failed = false;
          while(SubPosition < strlen(SubString))
             if(((Position + SubPosition) >= strlen(FullString)) || (FullString[Position + SubPosition] != SubString[SubPosition]))
                Failed = true;
          if(!Failed) cout << Position << " ";

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

  3. #3
    Registered User
    Join Date
    Jun 2002

    thank you!!

    Hello, thank you very much for the was exactly what I was trying to do...thanks again!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. char Handling, probably typical newbie stuff
    By Neolyth in forum C Programming
    Replies: 16
    Last Post: 06-21-2009, 04:05 AM
  2. Reusing a string pointer question
    By chiefmonkey in forum C++ Programming
    Replies: 3
    Last Post: 05-06-2009, 04:53 PM
  3. Program using classes - keeps crashing
    By webren in forum C++ Programming
    Replies: 4
    Last Post: 09-16-2005, 03:58 PM
  4. String array question
    By gogo in forum C++ Programming
    Replies: 6
    Last Post: 12-08-2001, 06:44 PM