Advertisement

how to parse a string

Started by April 11, 2002 10:20 PM
10 comments, last by GarlandIX 22 years, 7 months ago
quote: Original post by Oluseyi
Original post by GarlandIX
If there was a way to extract the information after the / into a vaiable instead, that would be great. Does anyone have any ideas because im stumped.

a.) See my post. C++, clean, efficient, and returns an array containing all the tokens (which you can then play with as you see fit).

b.) str[n]cpy.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions ]
Thanks to Kylotan for the idea! [/q]

Notice how i said i was using c-style strings before. I do not want to use STL because i do not know enough about it to feel confident when using it. Let me repeat this: I am using c-style strings, and i am looking for a simple way to extract the values before and after the slash into separate variables.


——————————
This pisses benjamin bunny off->If someone asks you "A penny for your thoughts" and you put your two cents in, do you get change?

------------------------------BASIC programmers don't die, they just GOSUB and don't return.
quote: Original post by GarlandIX
Notice how i said i was using c-style strings before. I do not want to use STL because i do not know enough about it to feel confident when using it.

Well, RTFM, man! STL strings are easy and have a much more natural syntax. See my sig for a link to the SGI STL site.

quote:
Let me repeat this: I am using c-style strings, and i am looking for a simple way to extract the values before and after the slash into separate variables.

strncpy (or strcpy, but I recommend the former). Did you even read my post? Of course, there are all sorts of dynamic memory allocation considerations with using C-strings. You have to malloc/new char[ strlen( tok ) + 1 ]; (where tok is the char * returned by strtok) and also remember to free/malloc the memory when you''re done.

Or you could just use std::string. "Lack of comfort" is a lame excuse. If we all claimed that we''d never learn anything new.

[ GDNet Start Here | GDNet Search Tool | GDNet FAQ | MS RTFM [MSDN] | SGI STL Docs | Google! | Asking Smart Questions ]
Thanks to Kylotan for the idea!

This topic is closed to new replies.

Advertisement