Remove a common "string"

I have data that looks like this

/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/atvSOLITAIRE/AppDelegate.swift
/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/atvSOLITAIRE/Drag_and_Drop.swift
/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/iPadSolitaire/AppDelegate.swift
/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/iPadSolitaire/SceneDelegate.swift
/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/notes.swift
/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/tableCELLS.swift

and I need to transform it to this

atvSOLITAIRE/AppDelegate.swift
atvSOLITAIRE/Drag_and_Drop.swift
iPadSolitaire/AppDelegate.swift
iPadSolitaire/SceneDelegate.swift
notes.swift/tableCELLS.swift

with another single string containing the common part
s="/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/"

While it would still be interesting for a generic solution…
I found one for this specific situation… turns out a previous variable already had the common string I need for this app…

define the string you want to remove and see if the other string starts with it
so instead of

s="/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/"

I’d have

s="/Volumes/Drive #1/SWIFT-Projects/"

if it does remove the matching part

I know what the Xojo code looks like

no idea about swift

but it cant be rocket science ?

no idea if swift has regex that can just do the search & replace

I know I could do that in Bbedit in about 2 seconds

you missed the point of the execise. In the original posting, I don’t KNOW what to remove… it needs to analyze the array and figure out what the common string (if any) is

oh that certainly wasnt clear from the description

start with the “common string” as the file thing from the first one you get handed

then the next one shorten that common string down until it IS what starts the next one

lather rise & repeat until you’ve processed them all

in Xojo its something like (all written in here so take it with a grain of salt)

dim common as string 

for I = 0 to countOfStrings

    if I = 0 then
        common = strings(i)
    end if

    if strings(i).beginswith(common) then
        // do nothing !
    else
            while strings(i).beginswith(common) = false and common <> ""
                 common = common.left(common.length - 1)
            wend
    end
next

note that this should give you something like

atvSOLITAIRE/AppDelegate.swift
atvSOLITAIRE/Drag_and_Drop.swift
iPadSolitaire/AppDelegate.swift
iPadSolitaire/SceneDelegate.swift
notes.swift
tableCELLS.swift

and common as

/Volumes/Drive #1/SWIFT-Projects/atvSOLITAIRE/