mIRC Home    About    Download    Register    News    Help

Print Thread
Joined: Nov 2004
Posts: 842
Jigsy Offline OP
Hoopy frood
OP Offline
Hoopy frood
Joined: Nov 2004
Posts: 842
I wanted to sort a range of tokens alphabetically depending on their case size.

At the moment a doesn't work because it does this:

Code:
$sorttok(z A b a Z y,32,a) > A a b y z Z


What I'm proposing is something like this:

Code:
$sorttok(z A b a Z y,32,A) > a b y z A Z
$sorttok(z A b a Z y,32,Ar) > Z A z y b a


What do you do at the end of the world? Are you busy? Will you save us?
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
$sorttokcs is a case sensitive version, did you overlook this one?

//echo -a $sorttokcs(z A b a Z y,32,a)

Edit: your order is not possible to get with $sorttok* though, $sorttok* uses the code point to sort the characterslooks like it's not an oversight, you really want a new option 'A' to get $sorttok* to put the uppercase letters after lowercases, instead of how it is currently: uppercase first.

Last edited by Wims; 13/08/18 06:05 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Jan 2004
Posts: 2,127
Hoopy frood
Offline
Hoopy frood
Joined: Jan 2004
Posts: 2,127
If you really want to flip the sort order of upper/lower case, you can invert the case of the string, then sort it, then invert the case of the sorted-string.

Code:
alias invert_case return $regsubex( $1- ,/([a-zA-Z])/g, $chr($xor($asc(\t),32)) )

//echo -a $invert_case($sorttokcs($invert_case(z A b a Z y),32,A))

Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
That's not efficient at all though, you can use one regex match to match all the uppercase at the beginning, capture them and the rest, and replace the match with \2 \1.


//echo -a $regsubex( A Z a b y z ,/^((?:\p{Lu}+ )*\p{Lu}+) (.*)/u,\2 \1)

But I'd say OP is looking for the built-in feature, that he already knows how to workaround it.


Last edited by Wims; 13/08/18 06:29 PM.

#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2003
Posts: 2,812
Hoopy frood
Offline
Hoopy frood
Joined: Feb 2003
Posts: 2,812
It's going to be long, but $ReplacExCS() is VERY FAST. Faster than $SortTok() or your $RegSubEx().

$replacexcs(%s,A,a,a,A,B,b,b,B,C,c,c,C,D,d,d,D,E,e,e,E,F,f,f,F,G,g,g,G,H,h,h,H,I,i,i,I,J,j,j,J,K,k,k,K,L,l,l,L,M,m,m,M,N,n,n,N,O,o,o,O,P,p,p,P,Q,q,q,Q,R,r,r,R,S,s,s,S,T,t,t,T,U,u,u,U,V,v,v,V,W,w,w,W,X,x,x,X,Y,y,y,Y,Z,z,z,Z)


Well. At least I won lunch.
Good philosophy, see good in bad, I like!
Joined: Jul 2006
Posts: 4,145
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 4,145
Well that's ok for Latin letters only, if you have to include non Latin letters.... grin


#mircscripting @ irc.swiftirc.net == the best mIRC help channel

Link Copied to Clipboard