Groups | Search | Server Info | Login | Register


Groups > comp.lang.awk > #9984

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

From gazelle@shell.xmission.com (Kenny McCormack)
Newsgroups comp.lang.awk
Subject Re: substr() - copying or not copying, that is here the question.
Date 2025-06-01 11:53 +0000
Organization The official candy of the new Millennium
Message-ID <101hevp$2qrh$1@news.xmission.com> (permalink)
References <101f9oo$18edp$1@dont-email.me> <683b5389$0$683$14726298@news.sunsite.dk> <101fv4s$1g5c8$1@dont-email.me> <87h60zrbea.fsf@bsb.me.uk>

Show all headers | View raw


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.

Back to comp.lang.awk | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

substr() - copying or not copying, that is here the question. Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-05-31 18:12 +0200
  Re: substr() - copying or not copying, that is here the question. mack@the-knife.org (Mack The Knife) - 2025-05-31 19:07 +0000
    Re: substr() - copying or not copying, that is here the question. Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-06-01 00:16 +0200
      Re: substr() - copying or not copying, that is here the question. Ben Bacarisse <ben@bsb.me.uk> - 2025-06-01 11:42 +0100
        Re: substr() - copying or not copying, that is here the question. Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-06-01 13:43 +0200
          Re: substr() - copying or not copying, that is here the question. gazelle@shell.xmission.com (Kenny McCormack) - 2025-06-01 12:06 +0000
            Re: substr() - copying or not copying, that is here the question. Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-06-01 15:27 +0200
        Re: substr() - copying or not copying, that is here the question. gazelle@shell.xmission.com (Kenny McCormack) - 2025-06-01 11:53 +0000
          Re: substr() - copying or not copying, that is here the question. Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-06-01 15:47 +0200
            Re: substr() - copying or not copying, that is here the question. gazelle@shell.xmission.com (Kenny McCormack) - 2025-06-01 14:17 +0000
              Re: substr() - copying or not copying, that is here the question. Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-06-08 00:01 +0200
      Re: substr() - copying or not copying, that is here the question. mack@the-knife.org (Mack The Knife) - 2025-06-03 06:56 +0000
        Re: substr() - copying or not copying, that is here the question. gazelle@shell.xmission.com (Kenny McCormack) - 2025-06-03 11:04 +0000
        Re: substr() - copying or not copying, that is here the question. Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-06-08 00:05 +0200
          Re: substr() - copying or not copying, that is here the question. mack@the-knife.org (Mack The Knife) - 2025-06-08 12:35 +0000
            Re: substr() - copying or not copying, that is here the question. Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-06-11 11:07 +0200
              Meta chat (Was: substr() - copying or not copying, that is here the question.) gazelle@shell.xmission.com (Kenny McCormack) - 2025-06-11 12:11 +0000
    Re: substr() - copying or not copying, that is here the question. Kaz Kylheku <643-408-1753@kylheku.com> - 2025-06-01 00:01 +0000

csiph-web