String Splitting
I am trying to translate this code to C++ from Java.
1 2 3
|
StringTokenizer split = new StringTokenizer(args[0], "@")'
user = split.nextToken();
host = split.nextToken();
| |
But I don't know if there is a class to do this
You can use boost::split(). There is more information on this at boost.org if you need it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
#include <iostream>
#include <string>
int main()
{
const std::string args[1] = { "james.parsons@cplusplus.com" } ;
auto pos = args[0].find( '@' ) ;
if( pos != std::string::npos )
{
const std::string user = args[0].substr( 0, pos ) ;
const std::string host = args[0].substr( pos+1 ) ;
std::cout << "user: " << user << " host: " << host << '\n' ;
}
}
| |
http://ideone.com/RwTkcD
Thanks :D
Topic archived. No new replies allowed.