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.

strings

Old posts that have not been replied to for several years.
Locked
S
Snapple
Voice
Posts: 38
Joined: Fri Jul 18, 2003 4:41 pm
Location: Israel
Contact:

strings

Post by Snapple »

hmm
is there a command to do like in mirc if (%var isin %var2)....
I mean, for example %var will be #Help
and %var2 will be #OperHelp #Help #Mirc
then it will return true
anyone know?
Snapple
There are 10 kind of people here, the one's who know binary code and the one's who don't.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Consult the string manual page.
Once the game is over, the king and the pawn go back in the same box.
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

Command: string match

Purpose: Test whether a given string matches a specified glob-style pattern.

Command Syntax: string match -nocase pattern string

Return Value: 1 if string matches pattern; 0 if not


The string match subcommand tests to see whether a
given string matches a specified glob-style pattern.
If you specify the -nocase option, the match is evaluated without regard to case.

If you don't use this option, you may end up with a different result than you intended.
For example, the character "_" lies between the upper-case and
lower-case ASCII letters in the Unicode collating sequence.

So if your pattern is [A-z], the underscore character will match the pattern.
If you intend to match only an alphabetic character,
you should specify -nocase and a pattern of [a-z].

Here's an example:

Code: Select all

set input "Help" 
set c_list "OperHelp Help Mirc"

  if {[string match -nocase "$input" "$c_list"]} {

Would return true 8)
I once was an intelligent young man, now i am old and i can not remember who i was.
S
Snapple
Voice
Posts: 38
Joined: Fri Jul 18, 2003 4:41 pm
Location: Israel
Contact:

thanks... but

Post by Snapple »

I already used string last... which working just fine, thanks.
hmm
I have another question, how can I remove from a string a part of it?
Snapple
There are 10 kind of people here, the one's who know binary code and the one's who don't.
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

this might work:

Code: Select all

set input "Help" 
set c_list "OperHelp Help Mirc"

proc update:list {} {
  global input c_list
  if {[string match -nocase "$input" "$c_list"]} {
    set position [lsearch -exact $c_list $input]
    set c_list [lreplace $c_list $position $position]
  }
}

give it a try
I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

First get it's position in the list with lsearch then remove it with lreplace.
Once the game is over, the king and the pawn go back in the same box.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Dedan wrote:this might work:

Code: Select all

set input "Help" 
set c_list "OperHelp Help Mirc"

proc update:list {} {
  global input c_list
  if {[string match -nocase "$input" "$c_list"]} {
    set position [lsearch -exact $c_list $input]
    set c_list [lreplace $c_list $position $position]
  }
}

give it a try
Since we are talking about strings this is NOT the way to go..
As mentioned numerous times on the forum, you can NOT treat strings as lists and visa versa without first doing conversions.

If there is particular text you are trying to remove from a string, might I suggest either using regsub or string map.
User avatar
Dedan
Master
Posts: 260
Joined: Wed Jul 09, 2003 10:50 pm
Location: Memphis

Post by Dedan »

Thanks strikelight.

Would you care to expand on the subject?

Sounds like a good candidate for the FAQ section.
I once was an intelligent young man, now i am old and i can not remember who i was.
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

Dedan wrote:Thanks strikelight.

Would you care to expand on the subject?

Sounds like a good candidate for the FAQ section.
Nothing I could say that hasn't already been said here in the forum,
and also @ http://www.peterre.com/characters.html
User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Also, do consult the regsub manual.
Once the game is over, the king and the pawn go back in the same box.
Locked