Re: split a string
From: Francis Glassborow (francis_at_robinton.demon.co.uk)
Date: 06/14/04
- Next message: as mellow as a horse: "Re: trying to call a virtual method from constructor of abstract object"
- Previous message: Chris \( Val \): "Re: return [] X"
- In reply to: Ronen Kfir: "split a string"
- Next in thread: Ronen Kfir: "Re: split a string"
- Reply: Ronen Kfir: "Re: split a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 14 Jun 2004 11:28:24 +0100
In article <b02d7807.0406140134.7906d43e@posting.google.com>, Ronen Kfir
<ronenk@tauex.tau.ac.il> writes
>Hi,
>
>I have a string of N characters. Inside this string planted one or
>more ‘*' characters, which are the delimiter for the substring.
>
>Example:
>
>dfka*kghe*c***mbmfkj
>
>I need to find the length of each substring. I have figured that in
>order to count the substrings I need to replace '*' with \0. How do I
>do that replacement? If I do that, how will the substrings will be
>allocated? How will I access them?
>Need to acomplish task without using slice() or any library function
>of family.
Then I think you have figured out wrong. Do not even dream of messing
with the characters. You should be able to achieve your objective with a
const qualified string (though I wish you had followed instructions and
told us whether you were writing C or C++ because the exact idiomatic
mechanisms are different in the two languages.
A very unpolished (i.e. I would give it a barely passing grade as a
teacher) solution in C is:
size_t mystrlen(char const ** source_ptr){
int count = 0;
char const * source = *source_ptr;
for(count; source[count]; ++count){
++(*source_ptr);
if(source[count] == '*') break;
}
return count;
}
-- Francis Glassborow ACCU Author of 'You Can Do It!' see http://www.spellen.org/youcandoit For project ideas and contributions: http://www.spellen.org/youcandoit/projects
- Next message: as mellow as a horse: "Re: trying to call a virtual method from constructor of abstract object"
- Previous message: Chris \( Val \): "Re: return [] X"
- In reply to: Ronen Kfir: "split a string"
- Next in thread: Ronen Kfir: "Re: split a string"
- Reply: Ronen Kfir: "Re: split a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|