Ofloo wrote:allready found a way
Code: Select all
foreach x [array names modesArray] {
puts "NICK [lindex [string map {\x5F\x23 \x20\x23} $x] 0] CHAN [strin map {\x20\x23 \x5F\x23} [join [lrange [string map {\x5F\x23 \x20\x23} $x] 1 end]]]]"
}
Looks like you're using lindex/lrange on a string there... and btw: there's nothing wrong with writing those chars directly in your code instead of using escapes. The escapes just add to the number of substitutions required and slow things down.
Here's a regexp to do the "splitting" for you (if you refuse to change the join to a single char

)
Code: Select all
regexp {^(.+?)_(#.*)$} $x nick nick chan
And here's why you should consider using a single char:
Code: Select all
# some test data
array set a {nick,#chan abc nick,#chan2 def nick,#chan3 ghi nick,#chan4 jkl nick,#chan5 mno}
# some tests
foreach way {
{foreach {n c} [split [join [array names a] ,] ,] {set xxx $n,$c}}
{foreach n [array names a] {scan $n {%[^,],%s} n c; set xxx $n,$c}}
{foreach n [array names a] {set i [expr {[string first ",#" $n]-1}]; set xxx [string range $n 0 $i],[string range $n [incr i 2] end]}}
{foreach n [array names a] {regexp {^(.+?),(.+)$} $n n n c; set xxx $n,$c}}
{foreach n [array names a] {set xxx [lindex [split [string map {, " "} $n]] 0],[join [lrange [split [string map {, " "} $n]] 1 end] ""]}}
} {
puts "[time $way 10000]: $way"
}
Run it and take a look at the times

The first one is similar to your first suggestion
The last one is roughly what you did in your final solution
The third way would also handle multiple chars (if you insist on that) and seems to be about twice as fast as your map/split/join/lrange+join thing
