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.

Reformat a sentence.

Old posts that have not been replied to for several years.
Locked
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Reformat a sentence.

Post by cerberus_gr »

Hello,

I have this sentence

Code: Select all

abcdef word1 word2 word3 word4 ::msg:: word_last
or
abcdsi word1 word2 ::msg:: word_last
abcdef or abcdsi: are words which change
word1-4: words I want
::msg:: standard
word_last: in could be 1-15 words

I want to set to a variable only word1-*, like:
word1 word2 word3 word4
or
word1 word2

Any help?
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

could be more specific i not realy sur what u mean do you wana create an array where u get

word(1) = ...
word(2) = ...

Code: Select all

foreach line $arg {
  if {[info exists i]} {
    incr i
  } else {
    set i 1
  }
  set word($i) "$line"
}
or do you want
the word before the last one
then do

Code: Select all

[lindex $arg end-1]
XplaiN but think of me as stupid
c
cerberus_gr
Halfop
Posts: 97
Joined: Fri Feb 07, 2003 8:57 am
Location: 127.0.0.1

Post by cerberus_gr »

I want something like

Code: Select all

regexp (:$)+ $str tmp; set file [lrange $tmp 1 end]
but I'm not sure if this is the best way.

(I don't know the usage of the regexp, so maybe the above to be wrong :P)
O
Ofloo
Owner
Posts: 953
Joined: Tue May 13, 2003 1:37 am
Location: Belguim
Contact:

Post by Ofloo »

honestly i don't have regexp fully covert could u plz just xplain think of me as stupid ;)
XplaiN but think of me as stupid
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Is this something of what you are after?

Code: Select all

set text "abcadf word1 word2 word3 ::msg:: morewords moremorewords"
regsub {[^ ]* ([^:]*) :[^ ]* (.*)} $text {\1 \2} text
Locked