This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

string editing

Help for those learning Tcl or writing their own scripts.
Post Reply
w
wiz(andrew)
Voice
Posts: 5
Joined: Fri Sep 01, 2006 7:47 am

string editing

Post by wiz(andrew) »

hello
i need few proc/command that match mirc's commands $mid

Code: Select all

  $mid(text,S,N) 
  Returns N characters starting at position S in text. 
  
  $mid(othello,3,4)  returns hell 
  
  If N is zero, it returns the number of characters from S to the end of the line. 
  
  You may also use negative numbers for S or N. 
what i am trying to is to take out lets say the secound char from a string etc..

string "abc 123 qwe"
then to take the 2chr "b" or the 5 till the 8 "123 "

Thx For the help
User avatar
krimson
Halfop
Posts: 86
Joined: Wed Apr 19, 2006 8:12 am

Post by krimson »

r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Try:

Code: Select all

proc mid {text s {n ""}} {
  if {[info exists n]} { 
    return "[string range $text [expr $s - 1] [expr $n - 1]]"
  } else { 
    return "[string length [string range $text [expr $s - 1] end]]"
  }
}
Not tested.
r0t3n @ #r0t3n @ Quakenet
w
wiz(andrew)
Voice
Posts: 5
Joined: Fri Sep 01, 2006 7:47 am

Post by wiz(andrew) »

Thx for the help!!!
(i dont belive i missed the string section in)


http://www.tcl.tk/man/tcl8.4/TclCmd/string.htm#M40 :oops:
thx again
Post Reply