Anonymous user
Find common directory path: Difference between revisions
m
Undo revision 78197 by Dkf (Talk) whoops; collided with other edits!
m (improve wording of task description) |
|||
Line 1:
{{task}}
Create a routine that
Test your routine using the forward slash '/' character as the directory separator and the following three strings as input paths:
Line 25:
=={{header|PureBasic}}==
PureBasic don't have a path comparator directly but instead have powerful string tools.
Simply by checking the catalog names until they mismatch and add up the correct parts, the task is accomplished.
<lang PureBasic>Procedure.s CommonPath(Array InPaths.s(1),separator.s="/")
<lang PureBasic>S1$="/home/user1/tmp/coverage/test"▼
Protected SOut$=""
S2$="/home/user1/tmp/covert/operator"▼
Protected i, j, toggle
S3$="/home/user1/tmp/coven/members"▼
If ArraySize(InPaths())=0
ProcedureReturn InPaths(0) ; Special case, only one path
EndIf
Repeat
i+1▼
toggle=#False
For j=1 To ArraySize(InPaths())
If (StringField(InPaths(j-1),i,separator)=StringField(InPaths(j),i,separator))
If Not toggle
SOut$+StringField(InPaths(j-1),i,separator)+separator
toggle=#True
EndIf
Else
ProcedureReturn SOut$
EndIf
Next
ForEver
EndProcedure</lang>
Example of implementation
<lang PureBasic>Dim t.s(2)
Debug CommonPath(t(),"/"))</lang>
▲ i+1
=={{header|Python}}==
|