extracting string 
Author Message
 extracting string

const char* big = "abcdefgh123" ;
const char* small = "bcd" ;

Now, I want to extract the remaining string from big, after the small
contents.
That is the result string should have "efgh123".

I am confused about how to do it ?

Please help! Thanks!



Mon, 12 Dec 2005 13:46:47 GMT  
 extracting string

Quote:

> const char* big = "abcdefgh123" ;
> const char* small = "bcd" ;

> Now, I want to extract the remaining string from big, after the small
> contents.
> That is the result string should have "efgh123".

> I am confused about how to do it ?

> Please help! Thanks!

strstr() is your friend. It will find your needle in the haystack, the
returned pointer will point to the beginning of the needle, adding
strlen(small) to that pointer will yield a pointer to the position after
that substring.

--

"LISP  is worth learning for  the profound enlightenment  experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days."   -- Eric S. Raymond



Mon, 12 Dec 2005 13:46:42 GMT  
 extracting string

Quote:

> const char* big = "abcdefgh123" ;
> const char* small = "bcd" ;

> Now, I want to extract the remaining string from big, after the small
> contents.
> That is the result string should have "efgh123".

If you are sure that `small' is present in `big':
        const char *remainder = strstr (big, small) + strlen (small);
--
"The way I see it, an intelligent person who disagrees with me is
 probably the most important person I'll interact with on any given
 day."
--Billy Chambless


Mon, 12 Dec 2005 13:59:31 GMT  
 extracting string
On 25 Jun 2003 22:46:47 -0700,

Quote:
> const char* big = "abcdefgh123" ;
> const char* small = "bcd" ;

> Now, I want to extract the remaining string from big, after the small
> contents.
> That is the result string should have "efgh123".

Use strstr(big, small) to find the first occurrence of small in big.
Add strlen(small) to the returned pointer. The result should now point
to the 'e' in big (IOW it's a pointer to the substring "efgh123" in
the string pointed to by big). Since I don't really know what you mean
by "the result string", and what you want to do with that, I can't
give you any more advice.

Martien
--
                        |
Martien Verbruggen      | Freudian slip: when you say one thing but
Trading Post Australia  | mean your mother.
                        |



Mon, 12 Dec 2005 13:58:12 GMT  
 extracting string

Quote:

> const char* big = "abcdefgh123" ;
> const char* small = "bcd" ;

> Now, I want to extract the remaining string from big, after the
> small contents. That is the result string should have "efgh123".

> I am confused about how to do it ?

char *p;

if ((p = strstr(big, small))) p += strlen(small);

--

   Available for consulting/temporary embedded and systems.
   <http://cbfalconer.home.att.net>  USE worldnet address!



Mon, 12 Dec 2005 18:34:22 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Extracting Strings passed from VB Array in MFC?

2. extracting string from struc

3. Extracting String IDs from Resource Dlls

4. Extracting strings from char

5. extract string routine

6. Extracting Strings from C/C++ source files

7. Extracting Strings from a file.

8. how can I use String.Substring() method extract string within " and "?

9. Extracting a set of characters from a string

10. extracting data from a string

11. Question on appending to a string extracted from a listbox

12. extract part of a string

 

 
Powered by phpBB® Forum Software