Posts: 128
Threads: 48
Joined: Jan 2007
Hi there,
I have a macro and everything what is found is stored in a string, is it possible to filter out the exact doubles/triples etc so if 99 is found twice (or more) it is not stored (and processed for later use) twice (or more times)
It would help me a lot if you could help me with this.
TIA
Posts: 12,099
Threads: 142
Joined: Dec 2002
Posts: 128
Threads: 48
Joined: Jan 2007
Well this should work i think, but how can i implement this in a macro  hock:
I mean in that topic you say 'create a member function' which i did but how can i tell my macro to process the data through this 'member function'?
I know i'm stupid
Thanks for your patience
Posts: 12,099
Threads: 142
Joined: Dec 2002
See EXAMPLE in the function. For example, if the text is stored in variable s, the code will be
s.RemoveDuplicateLines
Posts: 128
Threads: 48
Joined: Jan 2007
When i try this and i try to compile i get a errorcode 4 unknown member?
Is there a certain place to store these 'member functions' is it possible to give an example of code with a member function which is used and called?
TIA
Posts: 1,769
Threads: 410
Joined: Feb 2003
did you name the member function "RemoveDuplicateLines"
Posts: 12,099
Threads: 142
Joined: Dec 2002
Its name must be str.RemoveDuplicateLines
It can be anywhere.
The variable where the text is stored must be of type str.
str s
...
s.RemoveDuplicateLines
Posts: 128
Threads: 48
Joined: Jan 2007
I Called it RemoveDuplicateLines and the code i copy/pasted:
function [flags] ;;flags: 1 case insensitive
;EXAMPLE
;str s=
;;apple
;;apple
;;orange
;;apple
;;grape
;;orange
;
;s.RemoveDuplicateLines
if(!this.end("[]")) this+"[]"
str s ss
int i j
for i 0 1000000000
,j=s.getl(this i)
,if(j<0) break
,ss.from("[]" s "[]")
,this.findreplace(ss "[]" 8|(flags&1) "" j+s.len)
Something wrong with the procedure?
I placed the member function in the folder in which my macro also is.....
Posts: 1,769
Threads: 410
Joined: Feb 2003
in your macro, when you type your string variable (eg TestVar) and hit the "." can you see it at the bottom of the list that popsup?
Posts: 128
Threads: 48
Joined: Jan 2007
Posts: 1,769
Threads: 410
Joined: Feb 2003
that means you didn't make it a member function correctly
did you put "str." in front of the "RemoveDuplicateLines" part?
Posts: 128
Threads: 48
Joined: Jan 2007
At first i did, later i changed the name several times. Now i made it again and created a new member function named RemoveDuplicateLines without str. in front of it.
Posts: 1,769
Threads: 410
Joined: Feb 2003
it has to have the "str." in front.
Posts: 128
Threads: 48
Joined: Jan 2007
I don't get it,
I created a new one simular to the first one and it works now...
KEN thanks for your help, i'm very greatfull
Posts: 1,769
Threads: 410
Joined: Feb 2003
the name of the new member function has to be "str.RemoveDuplicateLines"
that first part tells qm what type of var can use the function ie strings not integers.
Posts: 128
Threads: 48
Joined: Jan 2007
After a few days i had the time to try it but it didn't work, i think it is my stupidity or something what i simply don't understand but i do a findrx over a piece of text with something like this:
findrx(s "(10|20|25)(?:\.\d{1,3}){3}" 0 4 a)
the result is 10.10.10.1010.10.10.1020.20.20.2010.10.10.1025.25.25.25
And with this i do a test for each ip so if there are doubles/triples it is inefficient..
And doesn't give something the member function can split, my questions are:
- is it possible to exclude doubles from the result or
- filter the doubles from this result in a decent way?
Thanks for your time in advance
Freggel
Posts: 1,769
Threads: 410
Joined: Feb 2003
it would be easier if you could put each of the ips into their own row.
can you do that by adding a "[]" to the string after you put the ip into it?
EDIT
04/03/2007 12:53:09 PM
also, you can put this into an ARRAY to deal with it as well.
Posts: 128
Threads: 48
Joined: Jan 2007
Don't know what you mean, i would like to if it helps but if i have a simple list like
10.10.10.10
20.20.20.20
25.25.25.25
and i search it with the findrx i see in the output field of qm
10.10.10.1020.20.20.2025.25.25.25
so if its possible to separate them by adding a [] then the member function will be able to search and clear i think...
Posts: 1,769
Threads: 410
Joined: Feb 2003
oh, if your ip are already in list form (one on each line) then just use the string function "RemoveDuplicateLines".
_s=
;apple
;apple
;orange
;apple
;grapei
;orange
_s.RemoveDuplicateLines
out _s
Posts: 128
Threads: 48
Joined: Jan 2007
That was just an example, most of the time i extract it from a piece of text and it is not like the example....
So if there is a possibility to store it like this and then the RemoveDuplicateLines it would be fine to me
TIA
Posts: 1,769
Threads: 410
Joined: Feb 2003
is there anyway you can do a search/replace to put in a "[]" before you do the rx find? then you can do a rx dump into an Array and then dump the Array into a string.
Posts: 128
Threads: 48
Joined: Jan 2007
I think if i do that it wil destroy my endresult, when i use a header for instance, i clean it up for further usage... So if i place [] in it, it will destroy the layout of the result....
Posts: 1,769
Threads: 410
Joined: Feb 2003
you could put it back into the "oneline" mode afterwards with a quick "findreplace".
Posts: 128
Threads: 48
Joined: Jan 2007
OK, I'll give it a try in a couple of hours..
Thanks for your time ! :!:
Posts: 128
Threads: 48
Joined: Jan 2007
Hi there,
I'm trying out now to replace ip with ip+[] but can't get it done. I seem to do something wrong:
s.replacerx(".+?(\d{1,3}){4}" ".+?(\d{1,3}){3}[]" 4)
First one seems to be replaced but rest is left alone
Any ideas?
Grz
Freggel99
Posts: 1,769
Threads: 410
Joined: Feb 2003
4 is "single replacement"
take that flag off and it should work.
Posts: 128
Threads: 48
Joined: Jan 2007
Thx Ken for your help, i've managed it finaly!
Your pathience was wonderfull!
|