Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #36639

Re: indexOf do not behave as i expected?

From "R.Wieser" <address@not.available>
Newsgroups comp.lang.javascript
Subject Re: indexOf do not behave as i expected?
Date 2019-05-23 07:59 +0200
Organization Aioe.org NNTP Server
Message-ID <qc5cs0$l8v$1@gioia.aioe.org> (permalink)
References <21c9b272-81ba-4da2-9c25-378447e0d635@googlegroups.com>

Show all headers | View raw


Jonas,

> I thought as LB added it would find first, second and third occurence and 
> so on.

The whole problem is that indexOf's second argument is not an occurence 
index, but a character (into the to-be-searched string).

In other words:  Initialize 'bnkEND' to 1 and alter
>   var bnkSTART = ATXT.indexOf("[",LB);
>   var bnkEND = ATXT.indexOf("]",LB);

to

>   var bnkSTART = ATXT.indexOf("[",bnkEND);
>   var bnkEND = ATXT.indexOf("]",bnkSTART);

>> Time to learn Regex!

"And now you've got two problems" :-)

Regards,
Rudy Wieser


Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

indexOf do not behave as i expected? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-22 02:38 -0700
  Re: indexOf do not behave as i expected? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-05-22 12:38 +0200
    Re: indexOf do not behave as i expected? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-22 03:53 -0700
    Re: indexOf do not behave as i expected? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-22 04:26 -0700
      Re: indexOf do not behave as i expected? Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-05-22 04:38 -0700
        Re: indexOf do not behave as i expected? JJ <jj4public@vfemail.net> - 2019-05-22 19:34 +0700
          Re: indexOf do not behave as i expected? Jon Ribbens <jon+usenet@unequivocal.eu> - 2019-05-22 13:48 +0000
    Re: indexOf do not behave as i expected? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2019-05-22 22:28 +0200
  Re: indexOf do not behave as i expected? "R.Wieser" <address@not.available> - 2019-05-23 07:59 +0200
    Re: indexOf do not behave as i expected? "R.Wieser" <address@not.available> - 2019-05-23 10:47 +0200

csiph-web