Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Remove doubles from string
#1
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
#2
Unique items in a list
#3
Well this should work i think, but how can i implement this in a macro Confusedhock:

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
#4
See EXAMPLE in the function. For example, if the text is stored in variable s, the code will be

s.RemoveDuplicateLines
#5
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
#6
did you name the member function "RemoveDuplicateLines"
An old blog on QM coding and automation.

The Macro Hook
#7
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
#8
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.....
#9
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?
An old blog on QM coding and automation.

The Macro Hook
#10
No it is not visible
#11
that means you didn't make it a member function correctly
did you put "str." in front of the "RemoveDuplicateLines" part?
An old blog on QM coding and automation.

The Macro Hook
#12
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.
#13
it has to have the "str." in front.
An old blog on QM coding and automation.

The Macro Hook
#14
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
#15
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.
An old blog on QM coding and automation.

The Macro Hook
#16
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
#17
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.
An old blog on QM coding and automation.

The Macro Hook
#18
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...
#19
oh, if your ip are already in list form (one on each line) then just use the string function "RemoveDuplicateLines".



Code:
Copy      Help
_s=
;apple
;apple
;orange
;apple
;grapei    
;orange


_s.RemoveDuplicateLines
out _s
An old blog on QM coding and automation.

The Macro Hook
#20
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
#21
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.
An old blog on QM coding and automation.

The Macro Hook
#22
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....
#23
you could put it back into the "oneline" mode afterwards with a quick "findreplace".
An old blog on QM coding and automation.

The Macro Hook
#24
OK, I'll give it a try in a couple of hours..

Thanks for your time ! :!: Big Grin
#25
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
#26
4 is "single replacement"
take that flag off and it should work.
An old blog on QM coding and automation.

The Macro Hook
#27
Thx Ken for your help, i've managed it finaly!

Your pathience was wonderfull!


Forum Jump:


Users browsing this thread: 1 Guest(s)