I would like to detect strings that have prefixes from another. In my case these are separate it by dots. For more understanding I give some examples.
I took a look over thesse posts but in my case does not work 100%.
Determine if one string is a prefix of another
How to check if a string "StartsWith" another string?
I have implemented the following code but the problem is that the example number 5 is false
if(child.substr(0, parent.length) != parent){
//different prefixes
}
I expect following outputs:
false:
1. parent="abc.xyz"
child="abc.xyz.pol"
2. parent="abc.xyz"
child="abc.xyz.pol.del"
3. parent="abc.xyz.pol"
child="abc.xyz.pol.del"
true:
4. parent="abc.xyz.pol"
child="abc.xyz.del"
5. parent="abc.xyz"
child="abc.xyzDel"
6. parent="abc.xyz"
child="abc.xyzDel.pol"