Re: Find second index in a string
From: Pritam (pritamganguly_at_gmail.com)
Date: 10/18/04
- Next message: Ralf Fassel: "Re: Find second index in a string"
- Previous message: Stefano: "Re: Problem with freewrap and encoding (please just give it a try)"
- In reply to: Arjen Markus: "Re: Find second index in a string"
- Next in thread: Ralf Fassel: "Re: Find second index in a string"
- Reply: Ralf Fassel: "Re: Find second index in a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 18 Oct 2004 04:09:43 -0700
Arjen Markus <arjen.markus@wldelft.nl> wrote in message news:<417364ED.EC93306B@wldelft.nl>...
> Pritam wrote:
> >
>
> >
> > Thanks you everyone for your time. That will solve my problem expect
> > for that the version of tcl i have do not support "-start" and "-all"
> > options. The erros I get while trying out your recommendations are
> >
> > # 1 > bad search mode "-all": must be -exact, -glob, or -regexp
> >
> > # 2> wrong # args: should be "lsearch ?mode? list pattern"
> >
> > Running on Redhat 9.1 default tcl/tk installation. I have tried out on
> > windows also,Tcl/Tk 8.3 for Windows, Binary Distribution but still get
> > the same results.
> >
> > Is there way out with the current version on tcl that I have.
> >
> > Thanks again.
> > Cheers
> > Pritam
>
> Sure:
>
> set first [lsearch $list "demo"]
> set second [lsearch [lrange $list [expr {$first+1}] end]
> set second [expr {$second+$first}]
>
> You will have to do the arithmetic yourself, that is all :)
>
> (A similar solution is possible when searching inside _strings_
> - note the difference: several people have warned against the
> assumption that any string can pose as a valid list!)
>
> Regards,
>
> Arjen
Thanks a lot Arjen. My problem is resolved.
The exact steps that works for me are
set list "This is a demo containing duplicate demo value"
set first [lsearch $list "demo"]
set next [lrange $list [ expr $first + 1] end]
set second [expr $first + [lsearch $next "demo"] ]
set second_demo_index [expr $second + 1]
Cheers
Pritam
- Next message: Ralf Fassel: "Re: Find second index in a string"
- Previous message: Stefano: "Re: Problem with freewrap and encoding (please just give it a try)"
- In reply to: Arjen Markus: "Re: Find second index in a string"
- Next in thread: Ralf Fassel: "Re: Find second index in a string"
- Reply: Ralf Fassel: "Re: Find second index in a string"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]