mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
I thought I had asked something like this before, but the search only returned the last 100 entries made by me, inspite of the fact that I had specified a 5 year period, and the search only brought me back to the beginning of 2007.

In any case, I'm looking for something that will allow my bot to recognize if the first letter (not the first character) in a nick is upper or lower case.

Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Code:
if ($left(<nick>,1) isupper) {  }
else {  }

Joined: Feb 2006
Posts: 546
J
Fjord artisan
Offline
Fjord artisan
J
Joined: Feb 2006
Posts: 546
couple of methods:

Code:
  var %x = 1
  while ($$mid($nick,%x,1) !isletter) inc %x
  if ($v1 isupper) {
    ; commands
  }


the extra $ in $$mid() makes it /halt if the nick contains no letters. you could also be sneaky and use if ($v1 < a) which checks it's upper case (lexicographic comparison) :P

or the regex method:

Code:
if ($regex($nick,/^[^a-zA-Z]*[A-Z]/)) {
  ; commands
}


which also checks it's uppercase


"The only excuse for making a useless script is that one admires it intensely" - Oscar Wilde
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
That would check the first character, which may be what I want, but some people use nicks that start with characters other than a letter, which is why I specified that I wanted to check the first letter, not the first character.

Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Here's a couple of regex-based methods.

Code:
alias startsupper return $iif($regex($1,/^[\W\d_]*(?=[^\d_])(\w)/) && $regml(1) isupper, $true, $false)
alias startsupper2 return $regex($1,/^[^a-zA-Z]*[A-Z]/)


Although $startsupper() is longer it should in theory be future-proof for if/when mIRC ever supports Unicode in isupper (by the looks of things it doesn't yet although I'm only using 6.2).

Edit: Fixed digit/underscore issue. Thanks qwerty!

Last edited by starbucks_mafia; 16/04/07 02:58 AM.

Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Thanks Jaytea: Since I want different commands performed depending on if the first letter of the person's nick is capitalized or not (and the fact that I don't understand the regex), it looks like the first code you provided me with would be best.

If you disagree, and think the regex would be better, I would appreciate an explanation of the regex. (actually, I wouldn't mind the explanation either way)

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Thanks starbucks_mafia, however, as I stated in my reply to Jaytea, I don't understand regex and I prefer to use code that I understand, even if it's longer.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
Since the set of allowed chars in nicknames is not that big (all servers I've seen so far conform to RFC 2812, regarding the allowed chars; only lengths of nicks vary), yet another alternative would be:
Code:
if ($asc($remove($nick,-,[,],\,`,_,^,$chr(123),|,$chr(125),0,1,2,3,4,5,6,7,8,9)) isnum 65-90) {
  echo -a first letter is uppercase
}




/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Sep 2005
Posts: 2,881
H
Hoopy frood
Offline
Hoopy frood
H
Joined: Sep 2005
Posts: 2,881
Oops, I didn't read your post carefully enough. Sorry.

Joined: Jan 2003
Posts: 2,523
Q
Hoopy frood
Offline
Hoopy frood
Q
Joined: Jan 2003
Posts: 2,523
These wouldn't match nicknames like "{2Cool}" or "_Bob_", as numbers and _ are neither letters nor \W.


/.timerQ 1 0 echo /.timerQ 1 0 $timer(Q).com
Joined: Dec 2002
Posts: 2,962
S
Hoopy frood
Offline
Hoopy frood
S
Joined: Dec 2002
Posts: 2,962
Yeah, messed that up didn't I? I edited the original post so nobody has to see my bugged code. Instead they can see working code that's ugly as sin with that added lookahead assertion, but I can't think of any other way that would support unicode.

Not that unicode support is probably even needed since this is for nicks...
And not that isupper even supports unicode yet, if it ever will...


Spelling mistakes, grammatical errors, and stupid comments are intentional.
Joined: Oct 2004
Posts: 14
C
Pikka bird
Offline
Pikka bird
C
Joined: Oct 2004
Posts: 14
of course:
Code:
If ( $asc( $left( $nick ,1)) <= 90 ) { echo character is uppercase}
else { echo character is lowercase }


edit: this asumes this is working from an event which sets $nick

Last edited by CakerX; 17/04/07 01:51 AM.
Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
Like I said to hixxy, this checks the first character, not the first letter, per my original post

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
I know you said you'd like to stay away from regex solutions, but in this case, they are the most elegant. Here are two different regex solutions that are relatively easy to understand.

First is this identifier:
Code:
alias firstletter { noop $regex($1,/([a-z])/i) | return $regml(1) }


This code simply returns the first letter from $1, whether it is upper or lowercase. You can do whatever you want with it. In this case you could do something like this:

... if ($firstletter($nick) isupper) echo -a $v1 is UPPER

An explanation of the regex:

/ = beginning of regex
( = beginning of capture group 1
[a-z] = any character from a-z (not case sensitive, see i below)
) = end of capture group
/ = end of regex
i = regex is case insensitive

------------------------------------------

The second identifier:
Code:
alias isfirstupper return $regex($1,/^[^a-z]*[A-Z]/)


This code returns 1 if the first letter is uppercase and 0 if the first letter is not uppercase. This code would be used like this:

... if ($isfirstupper($nick)) echo -a First character is UPPER

This regex is slightly more complex and more difficult to understand.

/ = beginning of regex
^ = beginning of string
[^a-z]* = 0 or more of any character that isn't a-z (IS case sensitive)
[A-Z] = any character from A-Z (IS case sensitive)
/ = end of regex

Basically, from the beginning of the string, if there are 0 or more characters except a-z (CS), followed by A-Z. The rest of the string is abandoned once the first A-Z is found.

-------------------------------------------

You want to stay away from regex, but I think the first regex example is simple enough that you may want to bend that rule a bit. ;P

-genius_at_work

Joined: Aug 2004
Posts: 7,252
R
RusselB Offline OP
Hoopy frood
OP Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
The only reason I wanted to stay away from regex, is because I don't understand it, however, you provided an explanation of the format for the regex code, and when I get a chance I'll look it over to make sure I understand it.

I wouldn't expect anyone to use a code that they didn't understand, and I won't use one that I don't understand, but I am willing to learn.

Joined: Oct 2005
Posts: 1,741
G
Hoopy frood
Offline
Hoopy frood
G
Joined: Oct 2005
Posts: 1,741
What you are asking for can be done with a simple while loop, but the first regex I gave does the exact same thing, just in the background where you can't see it.

Code:
alias firstletter1 {
  noop $regex($1,/([a-z])/i)
  return $regml(1)
}

alias firstletter2 { 
  var %i = 0, %ii = $len($1)
  while (%i < %ii) {
    inc %i
    if ($mid($1,%i,1) isalpha) return $v1
  }
}


Both of those codes should return the same thing.

-genius_at_work



Link Copied to Clipboard