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.
Help for those learning Tcl or writing their own scripts.
Lu5ck
Halfop
Posts: 43 Joined: Thu Dec 07, 2006 8:58 am
Post
by Lu5ck » Wed Oct 24, 2007 10:01 am
Hi all,
How do you add text to string? Something like insert or var + "this message" in other language.
Regards,
Lu5ck
CrazyCat
Revered One
Posts: 1334 Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:
Post
by CrazyCat » Wed Oct 24, 2007 10:42 am
Using append (for strings) or concat (for lists):
Code: Select all
append var "more text"
concat var "other stuffs"
Lu5ck
Halfop
Posts: 43 Joined: Thu Dec 07, 2006 8:58 am
Post
by Lu5ck » Thu Oct 25, 2007 9:01 am
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
w00f
Halfop
Posts: 49 Joined: Wed Oct 04, 2006 6:50 pm
Post
by w00f » Thu Oct 25, 2007 3:43 pm
Code: Select all
set test "This is just a test uh"
set test [concat [lrange $test 0 2] "OOPS" [lrange $test 3 end]]
Code: Select all
Tcl return: This is just OOPS a test uh
use
lrange to grab what you want.
nml375
Revered One
Posts: 2860 Joined: Fri Aug 04, 2006 2:09 pm
Post
by nml375 » Thu Oct 25, 2007 4:09 pm
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: Select all
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: Select all
set test "This is just a test uh"
set result [string replace $test 12 12 "OOPS "]
NML_375
Lu5ck
Halfop
Posts: 43 Joined: Thu Dec 07, 2006 8:58 am
Post
by Lu5ck » Mon Oct 29, 2007 9:43 am
Hi there,
Thank you for the help.
Regards,
Lu5ck
Lu5ck
Halfop
Posts: 43 Joined: Thu Dec 07, 2006 8:58 am
Post
by Lu5ck » Tue Oct 30, 2007 9:12 am
Hi there,
Is there a easiler way to do it if I wanted to add text infront of the string?
Regards,
Lu5ck
user
Posts: 1452 Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway
Post
by user » Tue Oct 30, 2007 9:52 am
Code: Select all
set String "the end."
set String "This is $String"
Have you ever read "The Manual"?
Lu5ck
Halfop
Posts: 43 Joined: Thu Dec 07, 2006 8:58 am
Post
by Lu5ck » Wed Oct 31, 2007 7:45 am
Hi there,
Thanks.
Regards,
Lu5ck