Home   Archive   Permalink



Enhancing my understanding of parse

I have solved this problem using brute force, but I am wondering if it could be done with parsing.
    
I have several thousand file names that include, as part of the name, a street address, like this:
    
00510 1800 W Old Shakopee RD-P1.tif
00510 1800 W Old Shakopee RD-P2.tif    
00510 1800 W Old Shakopee RD-P3.tif    
00510 9800 PENN AVE S-P1.tif    
00510 9800 PENN AVE S-P2.tif    
00510 9800 PENN AVE S-P3.tif    
    
I want to group them by the part of the name that is the address, which would be these parts:
    
1800 W OLD SHAKOPEE RD    
9800 PENN AVE S    
    
That initial number of 00510 can't be part of the grouping because it can be common to several groups. The remainder of the name can't be used for grouping because the names are different because of the P1, P2, etc.
    
Looking at each file name as a string, what I really need from each string is a substring starting at some delimiter (in this case the first space) and ending at some other delimiter (in this case the hyphen). (If I have to take that initial space as part of the substring that is no problem because I can trim it off.) I was thinking that, for generality, I could write function that would allow me to specify any starting and ending delimiter(s), but that might be pushing things a bit.
    
Does anyone know if something like this can be done with a parse rule?    
    
Thank you. I have my brute-force function operational so this is more for skill enhancement rather than urgent need.

posted by:   Steven White       20-Jul-2018/18:17:46-7:00



get-address: func [txt strt fnsh] [
    x: copy []
    parse/all txt [any [thru newline thru strt copy addr to fnsh (append x addr)]to end]
    x
]
    
my-text: {
00510 1800 W Old Shakopee RD-P1.tif
00510 1800 W Old Shakopee RD-P2.tif    
00510 1800 W Old Shakopee RD-P3.tif    
00510 9800 PENN AVE S-P1.tif    
00510 9800 PENN AVE S-P2.tif    
00510 9800 PENN AVE S-P3.tif
}
    
editor get-address my-text " " "-"

posted by:   Nick       21-Jul-2018/7:35:08-7:00



Name:


Message:


Type the reverse of this captcha text: "l m x ?"



Home