Email address obfuscation in effect -- please
click here to turn it off.
[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
- To: "MLUG Members" <EMAIL:PROTECTED>
- Subject: Re: [MLUG] String manipulation in C
- From: "Jonathan King" <EMAIL:PROTECTED>
- Date: Sun, 1 Jul 2007 22:03:50 -0400
- Delivery-date: Sun, 01 Jul 2007 21:04:20 -0500
- Dkim-signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=YhEEXmwYFNXucYEc7dtaUBLAP6O8XLMsXYFIytNhqOp6bckw6cUprDX8z9EpqggKaYx1b6hTHcOzdH8O/D8C7Jf0jmyA9P2Wo9Y8sPOodcC3vBeq8VtF8FYJ2TxXFRB0l0cKB7QJ1ZcWZeAIDkrxf+mVarSd9cYw9z2cu+mJnHU=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=aWQAhmpW/d7cz6a3kkRAZ3Unl/cyi0He2TssJNEwZp2xyo1gMLy2u92fubRRefSx7tCvb+jqQlfjh8ttKUIUvc0ul9yXhijDv0q33PRygjHML/gNXgF+CwpA/mAzFIBR0wY/7RQQlLAJ82sLIaroXapdF4/+KhPO0dn18ZIiHLU=
- Envelope-to: EMAIL:PROTECTED
- In-reply-to: <EMAIL:PROTECTED>
- References: <EMAIL:PROTECTED> <EMAIL:PROTECTED>
- Reply-to: MLUG Members <EMAIL:PROTECTED>
- Sender: EMAIL:PROTECTED
On 7/1/07, Stephen Montgomery-Smith <EMAIL:PROTECTED> wrote:
On Sun, 1 Jul 2007, Jack Smith wrote:
> I have a little problem that you guys might be able to solve. I am
> trying to find out where a short sequence of letters matches in a much
> longer sequence of letters. I can find the location of the first match,
> but I cannot make it find any subsequent matches and need to. After
> reading the GNU regex documentation, I don't think that the regexec()
> function searches beyond one match of pattern in string.
>
> So what I'd like to do is hack everything off of the first string after
> the end of the first match. If I am looking for "ABC" in the following
> string:
>
> XXXXXABCXXXXXABCXX
>
> I'd like to reduce the string to
>
> XXXXXABCXX
>
> after the first "ABC" is found so that the second match can be found. I
> cannot find a function that will copy the last n digits of a string into
> an array (sort of an opposite to strncpy()) so that I could simply
> cleave out anything before and including the match in string, then
> search the remainder.
>
> Any help would be appreciated.
This is actually much easier than you think. If the string s (which is
actually a pointer) contains
"abcdefgh"
then the string s+4 contains
"efgh"
So just put s+4 into your search function instead of s. No copying needed
(although if you wanted to copy it, just put s+4 into strncpy or strcpy or
whatever).
What he said. Connecting with another recent thread (on the D
programming language), this is the kind of thing that C does
exceptionally well. It should be noted, however, that there is a
related cost for some kinds of optimizations, because with pointer
arithmetic, it becomes difficult or even impossible to prove things
about the variables involved.
But all that said...unless your strings are absolutely huge, this
would seem to be the kind of thing that Perl could do even better than
C (at least the code would be shorter).
jking
_______________________________________________
members mailing list
EMAIL:PROTECTED
http://mlug.missouri.edu/mailman/listinfo/members