| View previous topic :: View next topic |
| Author |
Message |
Lu5ck Halfop
Joined: 07 Dec 2006 Posts: 43
|
Posted: Wed Oct 24, 2007 10:01 am Post subject: String |
|
|
Hi all,
How do you add text to string? Something like insert or var + "this message" in other language.
Regards,
Lu5ck |
|
| Back to top |
|
 |
CrazyCat Revered One

Joined: 13 Jan 2002 Posts: 1032 Location: France
|
|
| Back to top |
|
 |
Lu5ck Halfop
Joined: 07 Dec 2006 Posts: 43
|
Posted: Thu Oct 25, 2007 9:01 am Post subject: |
|
|
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 |
|
 |
w00f Halfop
Joined: 04 Oct 2006 Posts: 49
|
Posted: Thu Oct 25, 2007 3:43 pm Post subject: |
|
|
| 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 |
|
 |
nml375 Revered One
Joined: 04 Aug 2006 Posts: 2857
|
Posted: Thu Oct 25, 2007 4:09 pm Post subject: |
|
|
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 |
|
 |
Lu5ck Halfop
Joined: 07 Dec 2006 Posts: 43
|
Posted: Mon Oct 29, 2007 9:43 am Post subject: |
|
|
Hi there,
Thank you for the help.
Regards,
Lu5ck |
|
| Back to top |
|
 |
Lu5ck Halfop
Joined: 07 Dec 2006 Posts: 43
|
Posted: Tue Oct 30, 2007 9:12 am Post subject: |
|
|
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 |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Tue Oct 30, 2007 9:52 am Post subject: |
|
|
| Code: | set String "the end."
set String "This is $String" |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
Lu5ck Halfop
Joined: 07 Dec 2006 Posts: 43
|
Posted: Wed Oct 31, 2007 7:45 am Post subject: |
|
|
Hi there,
Thanks.
Regards,
Lu5ck |
|
| Back to top |
|
 |
|