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.

using lindex lrange .. ??

Old posts that have not been replied to for several years.
Locked
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

using lindex lrange .. ??

Post by Ofloo »

hmm i got a string ..? and that string contains spaces but once i use lindex or lrange the string the spaces are lost so how do i use lindex or lrange without lossing spaces ? or any other char ?
XplaiN but think of me as stupid
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

lindex and lrange are list commands, and do not work well on strings.

Use "split" to covert the string to a list first.

Second, lindex returns a single element from a list. As such, if you split using spaces, then you don't get and spaces in return.

lrange returns a list in the form of a range of list elements. If you need the space back after, convert it to a string using "join".

You would have to show an example if this doesn't help.
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

this sounds logic but could you give me an example so i can understand it mutch beter ..?

or is there an other beter way ?

i have tryed this set filepath [string map -nocase {" " "<sp>"} [join [lrange $arg 4 end]]]
XplaiN but think of me as stupid
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

[lindex $arg 0] returns the first element in $arg, but its a list, so to turn it into a string change it to [lindex [split $arg] 0]

[lrange $arg 0 end] returns the whole line in $arg (from first letter to last letter, its also a list. to turn it into a string change it to [join [lrange $arg 0 end]]
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

dude i know its only the from the 4th that i need it but for my space problem ...?

don't have char problem but a space problem its for file path and if a file path like windows contains spaces ..? also it could contain more then one space and its to add it from channel not the fetch it from hd so ..

this is the problem nothing else :p

Code: Select all

set filepath [string map -nocase {" " "<sp>"} [join [lrange $arg 4 end]]]
its only a fragment of a script hehe i am not talking about lost chars but lost spaces !!!!

but tnx for trying to help
XplaiN but think of me as stupid
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

never mind i figured it out tnx for the split suggestion that worked ;)
XplaiN but think of me as stupid
Locked