mIRC Homepage
Posted By: Kreuz123123 help with "$1's" - 31/05/11 12:12 AM
i have this in my script
Quote:
var %Citizen = $readini(Citizenship.ini,CitizensName,$nick)
var %ApproveOn = $3-5
var %ApprovedBy = $6
var %Country = $7

the ApproveOn has $3-5 to include Day Month and Year for each "$N"
the problem is with "ApprovedBy" there should be a name in sometimes the name has spaces and sometimes its just 1 word
i tried doing "$6-" or "$6-8" but then the problem is in the country if the 6th parameters continues it wont fill up the country and its a problem is there any easy way to sort this without making alot of if's?
Posted By: Riamus2 Re: help with "$1's" - 31/05/11 12:29 AM
Try this...

Code:
var %ApprovedBy = $gettok($1-,6--2,32)
var %Country = $0


Or even...

Code:
var %ApprovedBy = $($+($,6-,$calc($0 - 1)),2)
var %Country = $0



Just be aware that if the Country is omitted, it will mess up %ApprovedBy as well.
Posted By: Kreuz123123 Re: help with "$1's" - 31/05/11 01:02 AM
the canada variable "$0" returns the number of the word

edit: with both of them

edit: i played wit hthe Gettock a little bit and got this

Quote:
var %ApprovedBy = $gettok($1-,6--2,32)
var %Country = $gettok($1-,9--1,32)

works fine with 2-3 word names
is it alright to use? i mean it wont **** up anything right?
Posted By: Riamus2 Re: help with "$1's" - 31/05/11 01:05 AM
Oops. Sorry about that.

Code:
var %Country = $gettok($1-,-1,32)
Posted By: Tomao Re: help with "$1's" - 31/05/11 03:54 AM
I personally find /tokenize better than $gettok()
Posted By: Kreuz123123 Re: help with "$1's" - 31/05/11 06:56 AM
thanks, ah i got another question how do i line up my $1's?
i mean the "Approved by" can be long or short and the "Country" moves according to it so if i make 1 short name and 1 long name
when i post the messages the lines will be dancing anyway to fix the position?
Posted By: Riamus2 Re: help with "$1's" - 31/05/11 10:15 AM
You can use spaces.dll to help space it out based on the $len(). Just remember that it will not line up for everyone. Different fonts will make it look different even if it looks perfect for you.

Btw, I didn't notice your edit above. Don't use the 9--1 method for $gettok() because you don't know if it starts at $9 or some other number. Use the -1 I showed below your edit.

@Tomao: It was already tokenized (in that it's already in $1- form). Because only spaces are used as separators and because spaces can be in one of the items, tokenize isn't going to be of any use.
Posted By: Riamus2 Re: help with "$1's" - 31/05/11 11:19 AM
I was playing around some with a regex method and came up with this.

Code:
noop $regex($6-,/(.*)\s(\w*)/)
var %ApprovedBy = $regml(1)
var %Country = $regml(2)


Here's what that does... noop lets us use $regex to fill $regml(1) and $regml(2) without having any output. Inside $regex(), $6- tells it to only use the 6th word until the end, just like you'd do anywhere else. Because we know it starts at $6, we can do this. The two /'s are used to show the start and end of the regular expression (regex). The .* is used to match any number of characters and the () around it tells mIRC to put the results into $regml(1). \s is a space, so it's looking for a space after the "any number of characters". And the \w* will match any number "word" characters (this doesn't include spaces, which is the important part) and then the () tell mIRC to put the results into $regml(2).

Now, you need to look at this as a whole because it's not all done in steps like that or else the entire $6- will be in $regml(1) because of the "any number of characters" match. As a whole, it will look for "any number of characters, followed by a space, followed by any number of "word" characters." Because there is only one space in the regex, it knows that .* will be everything before the last word and \w* will be the last word.

Something to be aware of, however... as I mentioned, \w* matches and "word" characters. If you include anything else, it won't be included in the match. Punctuation, for example, is not part of \w* match. Because you're using a country, this should be okay, but think about it before using it.

For example, if the Country was written as S.Africa, only the S would be in $regml(2). If you think you'll use punctuation, or anything other than A through Z, a through z, 0 through 9, or _, then you might need to have the last part of this regex adjusted.

One final thing no matter what method you use... some countries are multiple words. I'm not sure if you've considered how that will work. Maybe you're just using abbreviations?
Posted By: Tomao Re: help with "$1's" - 31/05/11 06:50 PM
For %country, I'll use
Code:
 \S+
The \S+ will match just about any punctuation characters. It acts like one token, so to speak. However, it won't match more than one word separated by a space.
Posted By: Kreuz123123 Re: help with "$1's" - 31/05/11 07:21 PM
thanks mainly there wont be any multiple words countries hehe so i dont think i should be worried about that
Posted By: Tomao Re: help with "$1's" - 31/05/11 08:58 PM
As noted, you have to be sure that a country name doesn't contain punctuation characters if you choose to use \w* ; if uncertain, changing it to \S* should avoid that possibility.
Posted By: Kreuz123123 Re: help with "$1's" - 31/05/11 10:40 PM
i forgot to ask how should i use it? i mean will it work with the Spaces i used before?

i mean it doesnt work as i hoped to
Posted By: Riamus2 Re: help with "$1's" - 31/05/11 11:14 PM
If you use any of the methods listed, it should work. If you give an example of input, it would help to determine why it isn't working. In general, you just put any of those methods into the same location that you had the variables to begin with.
Posted By: Kreuz123123 Re: help with "$1's" - 31/05/11 11:40 PM
it solved:) thanks alot
© mIRC Discussion Forums