Need to check part of a string to see if it matches another string

mig_akira

Member
Joined
Nov 19, 2009
Messages
6
Programming Experience
Beginner
Hello everyone.

In an application, I have some folders and must check if one is "inside" another, as in:
folder1->folder2->folder3->folder4

It's important to check only if any of the above folders are inside folder1. The complete path of the folder is stored as a string in folder.path.

In the way the app is inplemented, i could use folder2.father to see who is the folder2's father (a string 'folder1\'). Problem is, if I check folder4.father, it'll show 'folder3\'. If I use folder4.path, it'll show the whole path and the strings won't match (I'm comparing folder1.path to folder4.path).

So what's the best way to compare only the beginning of the string to see if it matches folder1.path? For example, in folder3.path (which is 'folder1\folder2\folder3') I must get only 'folder1\', to match it with folder1.path (which is 'folder1\').

Thanks!
 
Back
Top