splitting a string into 2 strings c++
hey guys i have an array of strings that i need to split into 2 different string.
Code:
string title = " "Rebecca" "Alfred Hitchcock" ";
so far all the data is in one string called title
//need to break them into 2 strings, title and director
// title should contain = Rebecca
// director should contain alfred hitchcock
please help, which string fuctions can i use to split these 2 and remove the quotes???
Re: splitting a string into 2 strings c++
First your question has nothing to do with the Visual C++ Programming, So I will now move this thread to the appropriate forum.
Second, since you are trying to use std::string why don't you want to look at the std::string methods?
Re: splitting a string into 2 strings c++
Code:
string title = " "Rebecca" "Alfred Hitchcock" ";
This is not a valid string. If you want " inside of " then you need to escape the quote or alternatively have 'Rebecca' etc rather than "Rebecca".
Either
Code:
string title = " \"Rebecca\" \"Alfred Hitchcock\" ";
string title = " 'Rebecca' 'Alfred Hitchcock' ";
Is this a homework assignment?
Hint: Look at find() and substr() string methods.
Re: splitting a string into 2 strings c++
Re: splitting a string into 2 strings c++
The simplest and often forgotten option is to just scan the string char by char and do what ever you like with it.
Re: splitting a string into 2 strings c++
There's a level of abstraction available here with find and substr that I think would be better than a lower level scanning of the string char by char to find those quotes and the substrings between them.
Re: splitting a string into 2 strings c++
Quote:
Originally Posted by
laserlight
There's a level of abstraction available here with find and substr that I think would be better than a lower level scanning of the string char by char to find those quotes and the substrings between them.
For the OP requirement, I agree. :thumb: