Re: New question on strings



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


.