P
Peter Proost
Hi group, I want to compare path strings in order to sort them, assuming I
have got:
"a.txt"
"dir1\c.txt"
"e.txt"
"dir1\d.txt"
When I compare them using > "e.text" would be greater than "dir1\c.txt"
But I would like them to be sorted as followed
"a.txt"
"e.txt"
"dir1\c.txt"
"dir1\d.txt"
so I wrote the following function to compare the strings, but I was
wondering if I'm maybe missing some built in dot net function because for
the moment my function is lacking support for strings containing more than
one \
Private Function MyCompare(ByVal str1 As String, ByVal str2 As String) As
Boolean
str1 = LCase(str1)
str2 = LCase(str2)
If str1.IndexOf("\"c) <> -1 And str2.IndexOf("\"c) = -1 Then
Return True
Else
If str1.IndexOf("\"c) <> -1 And str2.IndexOf("\"c) <> -1 Then
If Mid(str1, 1, str1.IndexOf("\"c)) = Mid(str2, 1,
str2.IndexOf("\"c)) Then
Return Mid(str1, str1.IndexOf("\"c) + 2, str1.Length -
str1.IndexOf("\"c) + 2) > Mid(str2, str2.IndexOf("\"c) _ + 2, str2.Length -
str2.IndexOf("\"c) + 2)
Else
Return Mid(str1, 1, str1.IndexOf("\"c)) > Mid(str2, 1,
str2.IndexOf("\"c))
End If
Else
If str1.IndexOf("\"c) = -1 And str2.IndexOf("\"c) <> -1 Then
Return False
Else
If str1.IndexOf("\"c) = -1 And str2.IndexOf("\"c) = -1
Then
Return str1 > str2
End If
End If
End If
End If
End Function
Greetz,
Peter
have got:
"a.txt"
"dir1\c.txt"
"e.txt"
"dir1\d.txt"
When I compare them using > "e.text" would be greater than "dir1\c.txt"
But I would like them to be sorted as followed
"a.txt"
"e.txt"
"dir1\c.txt"
"dir1\d.txt"
so I wrote the following function to compare the strings, but I was
wondering if I'm maybe missing some built in dot net function because for
the moment my function is lacking support for strings containing more than
one \
Private Function MyCompare(ByVal str1 As String, ByVal str2 As String) As
Boolean
str1 = LCase(str1)
str2 = LCase(str2)
If str1.IndexOf("\"c) <> -1 And str2.IndexOf("\"c) = -1 Then
Return True
Else
If str1.IndexOf("\"c) <> -1 And str2.IndexOf("\"c) <> -1 Then
If Mid(str1, 1, str1.IndexOf("\"c)) = Mid(str2, 1,
str2.IndexOf("\"c)) Then
Return Mid(str1, str1.IndexOf("\"c) + 2, str1.Length -
str1.IndexOf("\"c) + 2) > Mid(str2, str2.IndexOf("\"c) _ + 2, str2.Length -
str2.IndexOf("\"c) + 2)
Else
Return Mid(str1, 1, str1.IndexOf("\"c)) > Mid(str2, 1,
str2.IndexOf("\"c))
End If
Else
If str1.IndexOf("\"c) = -1 And str2.IndexOf("\"c) <> -1 Then
Return False
Else
If str1.IndexOf("\"c) = -1 And str2.IndexOf("\"c) = -1
Then
Return str1 > str2
End If
End If
End If
End If
End Function
Greetz,
Peter