Re: New question on strings
- From: "tom.rmadilo" <tom.rmadilo@xxxxxxxxx>
- Date: Thu, 28 Feb 2008 07:28:21 -0800 (PST)
On Feb 28, 6:51 am, "Gerald W. Lester" <Gerald.Les...@xxxxxxx> wrote:
mark wrote:
mark <jjoyce1...@xxxxxxxxxxx> dixit:
My string is
BSBSBSBSBSBSBSBS\Important_info.ars BSBSBSBSBSBS
Retrieve the info between .ars and the first backslah to the left.
Any ideas?
% set str {BSBSBSBSBSBSBSBS\Important_info.ars BSBSBSBSBSBS}
% set first [string first \\ $str]
% set end [string first .ars $str]
% set target [string range $str [incr $first] [incr $end -1]]
OMG, is this another one of those regressions? I guess so. [Incr] now
auto initializes to zero if the variable doesn't exist. I wonder how
many infinite loops will be caused by this one? Imagine if our best
programmers make this mistake, how hard it will be for a newbie to
figure out why this code doesn't work?
I assume that [incr $first] should be [incr first]?
I wrote a quickie proc to help test out examples before I post them:
proc ::% { args } {
puts "% $args"
if {[catch {
puts [uplevel "$args"]
} err ]} {
global errorInfo
puts $errorInfo
}
}
In 8.4, variable 16 doesn't exist. In 8.5:
% set str {BSBSBSBSBSBSBSBS\Important_info.ars BSBSBSBSBSBS}
BSBSBSBSBSBSBSBS\Important_info.ars BSBSBSBSBSBS
% set first 16
16
% set end 31
31
% set target {}
Changing $first to first and $end to end:
% set str {BSBSBSBSBSBSBSBS\Important_info.ars BSBSBSBSBSBS}
BSBSBSBSBSBSBSBS\Important_info.ars BSBSBSBSBSBS
% set first 16
16
% set end 31
31
% set target Important_info
Important_info
.
- Follow-Ups:
- Re: New question on strings
- From: Gerald W. Lester
- Re: New question on strings
- From: Neil Madden
- Re: New question on strings
- References:
- New question on strings
- From: mark
- Re: New question on strings
- From: mark
- Re: New question on strings
- From: Gerald W. Lester
- New question on strings
- Prev by Date: serial communication with tcl
- Next by Date: Re: Tcl and the wiimote
- Previous by thread: Re: New question on strings
- Next by thread: Re: New question on strings
- Index(es):