egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

String

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Lu5ck
Halfop


Joined: 07 Dec 2006
Posts: 43

PostPosted: Wed Oct 24, 2007 10:01 am    Post subject: String Reply with quote

Hi all,

How do you add text to string? Something like insert or var + "this message" in other language.

Regards,
Lu5ck
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Oct 24, 2007 10:42 am    Post subject: Reply with quote

Using append (for strings) or concat (for lists):
Code:
append var "more text"
concat var "other stuffs"

_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Lu5ck
Halfop


Joined: 07 Dec 2006
Posts: 43

PostPosted: Thu Oct 25, 2007 9:01 am    Post subject: Reply with quote

Hi there,

Thanks for the answer. What if I want to add text into the center of the string or any location in the string.

Regards,
Lu5ck
Back to top
View user's profile Send private message
w00f
Halfop


Joined: 04 Oct 2006
Posts: 49

PostPosted: Thu Oct 25, 2007 3:43 pm    Post subject: Reply with quote

Code:

set test "This is just a test uh"
set test [concat [lrange $test 0 2] "OOPS" [lrange $test 3 end]]


Code:

Tcl return: This is just OOPS a test uh


use lrange to grab what you want.
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Thu Oct 25, 2007 4:09 pm    Post subject: Reply with quote

Errmmm.... NO!
First learn do tell the difference between lists and strings in tcl...
Add a { or such into the test-string and watch how your code falls apart...

Proper code would look something like this:
Code:

set test "This is just a test uh"
set list1 [split $test]
set list2 [list "This" "is" "just" "a" "test" "uh"]
set result1 [join [concat [lrange $test1 0 2] "OOPS" [lrange $test1 3 end]]]
linsert list2 3 "OOPS"


Edit:
In order to accomplish the same result without resorting to lists, use something like this:
Code:
set test "This is just a test uh"
set result [string replace $test 12 12 "OOPS "]

_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Lu5ck
Halfop


Joined: 07 Dec 2006
Posts: 43

PostPosted: Mon Oct 29, 2007 9:43 am    Post subject: Reply with quote

Hi there,

Thank you for the help.

Regards,
Lu5ck
Back to top
View user's profile Send private message
Lu5ck
Halfop


Joined: 07 Dec 2006
Posts: 43

PostPosted: Tue Oct 30, 2007 9:12 am    Post subject: Reply with quote

Hi there,

Is there a easiler way to do it if I wanted to add text infront of the string?

Regards,
Lu5ck
Back to top
View user's profile Send private message
user
 


Joined: 18 Mar 2003
Posts: 1452
Location: Norway

PostPosted: Tue Oct 30, 2007 9:52 am    Post subject: Reply with quote

Code:
set String "the end."
set String "This is $String"

_________________
Have you ever read "The Manual"?
Back to top
View user's profile Send private message
Lu5ck
Halfop


Joined: 07 Dec 2006
Posts: 43

PostPosted: Wed Oct 31, 2007 7:45 am    Post subject: Reply with quote

Hi there,

Thanks.

Regards,
Lu5ck
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber