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 help

Old posts that have not been replied to for several years.
Locked
l
loser
Voice
Posts: 10
Joined: Sat Jul 09, 2005 11:27 pm

string help

Post by loser »

if i said ".hello my name is loser" in the main?
how can i get "my" & "name" & "is" & "loser" in different vars?
t
tuete
Voice
Posts: 2
Joined: Tue Jul 26, 2005 2:53 am

Post by tuete »

the easiest way is to split your string into a list, then you can access the single list elements.

Code: Select all

set mystring "hello my name is loser"
set list [split $mystring " "]
set element [lrange $list 0 0]
in this example the var element would contain "hello". try to experiment with the numbers, they tell lrange wich element of the list to take.

greetings
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Re: string help

Post by Sir_Fz »

loser wrote:if i said ".hello my name is loser" in the main?
how can i get "my" & "name" & "is" & "loser" in different vars?
This should give you and idea:

Code: Select all

set string "my name is loser"
for {set i 0} {$i<[llength [split $string]]} {incr i} {
 set element($i) [lindex [split $string] $i]
}
Now you'll have:
$element(0) = my
$element(1) = name
$element(2) = is
$element(3) = loser
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

And to output these elements use:

Code: Select all

foreach e [array names element] {
 puthelp "PRIVMSG $chan :$element($e)"
}
Locked