string parsing
-
i have a string login#user#1 username password i want to trim login# and extract user#1 username password i am unable to sole it using strtok please help
Use
std::string::find_first_of()
To find the position of #. Then use
std::string::substring()
to extract the string you required. Code might look like this:
std::string test = login#user#1 username password;
size_t pos = test.find_first_of("#");
std::string requiredstr = test.substr(pos+1); -
Use
std::string::find_first_of()
To find the position of #. Then use
std::string::substring()
to extract the string you required. Code might look like this:
std::string test = login#user#1 username password;
size_t pos = test.find_first_of("#");
std::string requiredstr = test.substr(pos+1); -
Yes. strchr() also returns a pointer to a first occurence of a character in a string. For this you've to assign your input string to a
char *
variable. The following link might help: http://www.cplusplus.com/reference/clibrary/cstring/strchr/[^]
-
Yes. strchr() also returns a pointer to a first occurence of a character in a string. For this you've to assign your input string to a
char *
variable. The following link might help: http://www.cplusplus.com/reference/clibrary/cstring/strchr/[^]
-
hey i am programming in C...can u give a sample code of how to do it using strchr(), strtok or any other function in C
http://msdn.microsoft.com/en-us/library/2c8d19sb(v=vs.71).aspx[^]
«_Superman_» _I love work. It gives me something to do between weekends.
-
hey i am programming in C...can u give a sample code of how to do it using strchr(), strtok or any other function in C
I've provided you a link with source code. Use the formula in the printf statement inside the while loop. char str[] = "Your string goes here"; char * pch; printf ("Looking for the '#' character in \"%s\"...\n",str); pch=strchr(str,'s'); while (pch!=NULL) { printf ("found at %d\n",pch-str+1); pch=strchr(pch+1,'s'); } pch is the required string.
-
http://msdn.microsoft.com/en-us/library/2c8d19sb(v=vs.71).aspx[^]
«_Superman_» _I love work. It gives me something to do between weekends.
-
yeah i know this but this does not work for the string Login#User#1 username password if want to trim Login# and extract User#1 username password
You should be able to figure out what changes to the program needs to be made for it to work with your string.
«_Superman_» _I love work. It gives me something to do between weekends.
-
i have a string login#user#1 username password i want to trim login# and extract user#1 username password i am unable to sole it using strtok please help
Use
strchr()
to find the first # character, and then you can usestrtok()
to split into the three tokens delimited by spaces.Unrequited desire is character building. OriginalGriff I'm sitting here giving you a standing ovation - Len Goodman
-
i have a string login#user#1 username password i want to trim login# and extract user#1 username password i am unable to sole it using strtok please help
After so many questions regarding strings, parsing and related stuff, don't you think it's about time to read some actual books or articles to learn all this? Or do you intend to keep asking for the rest of your life? Seriously, the time you keep spending on low level programming questions like this would have been better spent by reading up and learning something by yourself. You are doing yourself and everyone else a disservice by asking questions without ever even trying to look something up and really understand the things you are dealing with. Regarding this particular question, simply reading up on strtok would solve it, easily.
-
i have a string login#user#1 username password i want to trim login# and extract user#1 username password i am unable to sole it using strtok please help
Have you tried something like:
char *pszSource = "login#user#1 username password";
char *pszPos = strstr(pszSource, "user#1");
// at this point, you could use pszPos with strcpy()
int nLen = pszSource - pszPos;"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"Show me a community that obeys the Ten Commandments and I'll show you a less crowded prison system." - Anonymous