Thread: Find text in quotes of string.

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    2

    Find text in quotes of string.

    If a string held this:
    Code:
    name { "cube01" }
    What would be an efficient way to copy what's in the quotes to a new string?

  2. #2
    Or working on it anyways mramazing's Avatar
    Join Date
    Dec 2005
    Location
    Lehi, UT
    Posts
    121
    strcpy(char *dest, const char *source)
    -- Will you show me how to c++?

  3. #3
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    once you locate the first quote, iterate through the string until you find the last one.

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    2
    Quote Originally Posted by Elkvis View Post
    once you locate the first quote, iterate through the string until you find the last one.
    Thanks.
    I was able to use the find function to find the quote's position, and then use copy to copy the name.

    Code:
    tester="\"";
    findPos=line.find(tester); //finds first quote mark
    findPos2=line.find(tester, findPos+1); //finds second quote mark
    length=line.copy(name, (findPos2-findPos-1), findPos+1); //copies the name into name
    name[length]='\0'; //end it off
    cout<<"Name: "<<name<<"\n";

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Message class ** Need help befor 12am tonight**
    By TransformedBG in forum C++ Programming
    Replies: 1
    Last Post: 11-29-2006, 11:03 PM
  2. Stripping quotes from a string
    By -W0kk3L- in forum C Programming
    Replies: 3
    Last Post: 03-15-2006, 01:03 PM
  3. Replies: 4
    Last Post: 03-03-2006, 02:11 AM
  4. A bunch of Linker Errors...
    By Junior89 in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2006, 02:59 PM
  5. lvp string...
    By Magma in forum C++ Programming
    Replies: 4
    Last Post: 02-27-2003, 12:03 AM