mIRC Home    About    Download    Register    News    Help

Print Thread
#80622 25/04/04 05:08 PM
Joined: Feb 2004
Posts: 119
D
da_hype Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Feb 2004
Posts: 119
To check check a string if there is no comma i use this right?

if (, !isin $1) { }

but how the i make it check if "before and after the comma" there is no space? like "testing,testing" and not
"testing, testing" or "testing ,testing" or any other similar combination???

#80623 25/04/04 05:13 PM
Joined: Nov 2003
Posts: 2,321
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,321
$regex($1-,/\S $+ $chr(44) $+ \S/)

#80624 25/04/04 05:30 PM
Joined: Feb 2004
Posts: 119
D
da_hype Offline OP
Vogon poet
OP Offline
Vogon poet
D
Joined: Feb 2004
Posts: 119
when i add

if $regex($1-,/\S $+ $chr(44) $+ \S/) { } it don't give the result i want.

I need to like this..
if (, !isin $1) { run command }
where if there is a space before a comma, after it.. or both... it will halt.

Or did i use $regex wrongly? (me not used to $regex)

#80625 25/04/04 05:36 PM
Joined: Nov 2003
Posts: 2,321
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Nov 2003
Posts: 2,321
Code:
var %i = 1, %err
while $pos($1-,$chr(44),%i) {
  if $mid($1-,$calc($pos($1-,$chr(44),%i) -1),1) == $chr(32) || $mid($1-,$calc($pos($1-,$chr(44),%i) +1),1) == $chr(32) { %err = 1 }
  inc %i
}
if !%err { dostuff }


#80626 25/04/04 06:02 PM
Joined: Feb 2004
Posts: 2,013
F
Hoopy frood
Offline
Hoopy frood
F
Joined: Feb 2004
Posts: 2,013
Hi,

the following is slightly better (not being picky, huh tidy :tongue:) because it will immediately halt your script when it matched a space before or after the comma, where in tidy's script it will keep processing, until all commas were found. Also i use var %y = $ifmatch, so that your script doesnt need to look up the position again, it's stored in a variable, which is also slighly faster. Either way works though

Code:
var %x = 1, %y
while $pos($1-,$chr(44),%x) {
 %y = $ifmatch
  if $mid($1-,$calc(%y -1),1) == $chr(32) || $mid($1-,$calc(%y +1),1) == $chr(32) { return }
  inc %x
}
commands  

You could make a custom identifier like this:
Code:
 
alias chk.comma {
  var %x = 1, %y
  while $pos($1-,$chr(44),%x) {
    %y = $ifmatch
    if $mid($1-,$calc(%y -1),1) == $chr(32) || $mid($1-,$calc(%y +1),1) == $chr(32) { return true }
    inc %x
  }
} 

Then simply use this in your script:
Code:
 
if !$chk.comma($1-) { do stuff } 


Although I'm positive that a well written $regex is surely faster, though I'm not familiar enough with em to make a decent one.


Edit:
Code:

alias chk.comma var %re = /(\s*\,\s+|\s+\,\s*)/ | if $regex($1-,%re) { return true }  


Hehe, it worx, but well, im sure it can be optimized a lot.

Enjoy

Last edited by FiberOPtics; 25/04/04 06:37 PM.
#80627 25/04/04 07:03 PM
Joined: Dec 2002
Posts: 1,893
O
Hoopy frood
Offline
Hoopy frood
O
Joined: Dec 2002
Posts: 1,893
Quote:
if there is a space before a comma, after it..

//var %text = test, test | if $regex(%text,/ \x2C|\x2C /) { echo -a indeed }
//var %text = test, test | if $count(%text,$chr(32) $+ $chr(44),$chr(44) $+ $chr(32)) { echo -a indeed }

#80628 26/04/04 06:29 AM
Joined: Aug 2003
Posts: 325
W
Fjord artisan
Offline
Fjord artisan
W
Joined: Aug 2003
Posts: 325
try this code:

if ( !$wildtok($1-,$+(*?,$chr(44),?*),0,32) ) { return }

or if you wish to make an alias/identifier:

alias chk, return $iif($wildtok($1-,$+(*?,$chr(44),?*),0,32),$true,$false)

then use: if ( !$chk,($1-) ) { return }

What's happening?
in $wildtok, first the $+(...) is piece the *?, the $chr(44) (the comma) and the ?* together so it's doing a wild search for *?,?*, where the * means anything, and the ? makes at least 1 character required. Since the tokens are spaces (32 as the last parameter), it doesn't count spaces as matching the ? requirement. therefore, SOMETHING must be there. ?,? would require 1 character, a comma and 1 character after that, the *'s at the front and end expand it to allow more.

The "0" in the line makes $wildtok to return the total number of matches, and if it's 0, then you have no test,test or whatever,whateverelse in your text. smile

Whats nice is that you can use $wildtok to get each matching token/item as you need it, if it works with what you are doing.

grin


Link Copied to Clipboard