Re: substr() - copying or not copying, that is here the question.

Liste des GroupesRevenir à cl awk 
Sujet : Re: substr() - copying or not copying, that is here the question.
De : gazelle (at) *nospam* shell.xmission.com (Kenny McCormack)
Groupes : comp.lang.awk
Date : 01. Jun 2025, 12:53:29
Autres entêtes
Organisation : The official candy of the new Millennium
Message-ID : <101hevp$2qrh$1@news.xmission.com>
References : 1 2 3 4
User-Agent : trn 4.0-test77 (Sep 1, 2010)
In article <87h60zrbea.fsf@bsb.me.uk>, Ben Bacarisse  <ben@bsb.me.uk> wrote:
...
An alternative (depending on the context) would be to consider an
extension that provides an index function with a third argument giving
the initial offset.  I've not looked at how extensions get access to
GAWK strings, so this many not be as easy as it sounds, but I would
guess that it might be relatively simple to do.

The thing about writing GAWK extensions is that the first one is hard,
because it is all new stuff to learn (and you have to establish your own
conventions for how your extensions are going to look, code-wise).  But once
you've written one, the second is much easier and it gets progressively
easier after that.  You want to get to a point where to write a new
extension, you just take the previous one you wrote, copy it to a new name,
do a global search/replace of "oldname" with "newname", delete the
operative code from the old extension, replace it with the new operative
code (which is usually a very small amount of actual code) - and, you're done.

I think that an index()-like function that starts the search at a given
offset into the main string (say, position 900000 of a one million
character string) would be both a good idea and pretty easy to implement as
an extension.  I could do it - at least modulo i18n.  My version would be
C locale only.  Note that index() doesn't do regexps; the search would be
straight string only - using strstr() (or strcasestr() if IGNORECASE is
set).

By the way, if you find the substring at position 900005 (i.e., the 5th (*)
char of the searched string), should the function return 5 or 900005?

(*) Or 6th; I'm not sure of my exact notation at this point.

--
People often ask what is the difference between liberals and conservatives.
It is this. Libs see the government helping them and are OK with the government
also helping other people.  Cons see the government screwing them and are OK
with that as long as the government is also screwing other people.

Date Sujet#  Auteur
31 May 25 * substr() - copying or not copying, that is here the question.18Janis Papanagnou
31 May 25 `* Re: substr() - copying or not copying, that is here the question.17Mack The Knife
31 May 25  +* Re: substr() - copying or not copying, that is here the question.15Janis Papanagnou
1 Jun 25  i+* Re: substr() - copying or not copying, that is here the question.8Ben Bacarisse
1 Jun 25  ii+* Re: substr() - copying or not copying, that is here the question.3Janis Papanagnou
1 Jun 25  iii`* Re: substr() - copying or not copying, that is here the question.2Kenny McCormack
1 Jun 25  iii `- Re: substr() - copying or not copying, that is here the question.1Janis Papanagnou
1 Jun 25  ii`* Re: substr() - copying or not copying, that is here the question.4Kenny McCormack
1 Jun 25  ii `* Re: substr() - copying or not copying, that is here the question.3Janis Papanagnou
1 Jun 25  ii  `* Re: substr() - copying or not copying, that is here the question.2Kenny McCormack
7 Jun 25  ii   `- Re: substr() - copying or not copying, that is here the question.1Janis Papanagnou
3 Jun 25  i`* Re: substr() - copying or not copying, that is here the question.6Mack The Knife
3 Jun 25  i +- Re: substr() - copying or not copying, that is here the question.1Kenny McCormack
7 Jun 25  i `* Re: substr() - copying or not copying, that is here the question.4Janis Papanagnou
8 Jun 25  i  `* Re: substr() - copying or not copying, that is here the question.3Mack The Knife
11 Jun 25  i   `* Re: substr() - copying or not copying, that is here the question.2Janis Papanagnou
11 Jun 25  i    `- Meta chat (Was: substr() - copying or not copying, that is here the question.)1Kenny McCormack
1 Jun 25  `- Re: substr() - copying or not copying, that is here the question.1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal