mIRC Home    About    Download    Register    News    Help

Print Thread
#232343 31/05/11 12:12 AM
K
Kreuz123123
Kreuz123123
K
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?

#232344 31/05/11 12:29 AM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
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.

Last edited by Riamus2; 31/05/11 12:38 AM.
K
Kreuz123123
Kreuz123123
K
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?

Last edited by Kreuz123123; 31/05/11 01:05 AM.
#232346 31/05/11 01:05 AM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
Oops. Sorry about that.

Code:
var %Country = $gettok($1-,-1,32)

Last edited by Riamus2; 31/05/11 02:36 AM.
Joined: Jul 2007
Posts: 1,124
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,124
I personally find /tokenize better than $gettok()

Tomao #232348 31/05/11 06:56 AM
K
Kreuz123123
Kreuz123123
K
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?

Last edited by Kreuz123123; 31/05/11 06:57 AM.
#232349 31/05/11 10:15 AM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
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.

Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
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?

Last edited by Riamus2; 31/05/11 11:44 AM.
Joined: Jul 2007
Posts: 1,124
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,124
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.

Last edited by Tomao; 31/05/11 07:08 PM.
K
Kreuz123123
Kreuz123123
K
thanks mainly there wont be any multiple words countries hehe so i dont think i should be worried about that

#232362 31/05/11 08:58 PM
Joined: Jul 2007
Posts: 1,124
T
Hoopy frood
Offline
Hoopy frood
T
Joined: Jul 2007
Posts: 1,124
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.

Tomao #232365 31/05/11 10:40 PM
K
Kreuz123123
Kreuz123123
K
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

Last edited by Kreuz123123; 31/05/11 10:49 PM.
#232366 31/05/11 11:14 PM
Joined: Oct 2004
Posts: 8,061
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Oct 2004
Posts: 8,061
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.

K
Kreuz123123
Kreuz123123
K
it solved:) thanks alot

Last edited by Kreuz123123; 01/06/11 12:29 AM.

Link Copied to Clipboard