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
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook) 2 2107
"Peter Proost" <pp*****@nospam .hotmail.comsch rieb im Newsbeitrag
news:eI******** ******@TK2MSFTN GP06.phx.gbl...
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
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)
You may want to try this:
Public Class Comparer
Implements IComparer(Of String)
Public Function Compare(ByVal x As String, ByVal y As String) As Integer
Implements System.Collecti ons.Generic.ICo mparer(Of String).Compare
Dim numOfPSS_x As Integer = GetNumberOfPath SeparatorSigns( x)
Dim numOfPSS_y As Integer = GetNumberOfPath SeparatorSigns( y)
If numOfPSS_x = numOfPSS_y Then
Return x.CompareTo(y)
Else
If numOfPSS_x numOfPSS_y Then
Return 1
Else
Return -1
End If
End If
End Function
Private Shared Function GetNumberOfPath SeparatorSigns( ByVal x As String)
As Integer
Dim count As Integer = 0
For i As Integer = 0 To x.Length - 1
If x.Chars(i) = "\"c Then
count += 1
End If
Next
Return count
End Function
End Class
Private Sub Test()
Dim stringList As New List(Of String)
stringList.Add( "e.txt")
stringList.Add( "dir1\c.txt ")
stringList.Add( "dir1\d.txt ")
stringList.Add( "a.txt")
stringList.Sort (New Comparer())
For Each s As String In stringList
Debug.Print(s)
Next
End Sub
Hope this is correct.
Robert
--
e-mail: r_.s_chnei_der\ wein_gart_ner.c om (remove all '_' and replace '\'
with
'@')
Thanks that seems to do the job
thanks again
Peter
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)
"Robert Schneider" <lo*******@the. postingschreef in bericht
news:ey******** ******@TK2MSFTN GP06.phx.gbl...
"Peter Proost" <pp*****@nospam .hotmail.comsch rieb im Newsbeitrag
news:eI******** ******@TK2MSFTN GP06.phx.gbl...
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
--
Programming today is a race between software engineers striving to build
bigger and better idiot-proof programs, and the Universe trying to
produce
bigger and better idiots. So far, the Universe is winning. (Rich Cook)
You may want to try this:
Public Class Comparer
Implements IComparer(Of String)
Public Function Compare(ByVal x As String, ByVal y As String) As
Integer
Implements System.Collecti ons.Generic.ICo mparer(Of String).Compare
Dim numOfPSS_x As Integer = GetNumberOfPath SeparatorSigns( x)
Dim numOfPSS_y As Integer = GetNumberOfPath SeparatorSigns( y)
If numOfPSS_x = numOfPSS_y Then
Return x.CompareTo(y)
Else
If numOfPSS_x numOfPSS_y Then
Return 1
Else
Return -1
End If
End If
End Function
Private Shared Function GetNumberOfPath SeparatorSigns( ByVal x As
String)
As Integer
Dim count As Integer = 0
For i As Integer = 0 To x.Length - 1
If x.Chars(i) = "\"c Then
count += 1
End If
Next
Return count
End Function
End Class
Private Sub Test()
Dim stringList As New List(Of String)
stringList.Add( "e.txt")
stringList.Add( "dir1\c.txt ")
stringList.Add( "dir1\d.txt ")
stringList.Add( "a.txt")
stringList.Sort (New Comparer())
For Each s As String In stringList
Debug.Print(s)
Next
End Sub
Hope this is correct.
Robert
--
e-mail: r_.s_chnei_der\ wein_gart_ner.c om (remove all '_' and replace '\'
with
'@') This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robin Siebler |
last post by:
I have two directory trees that I want to compare and I'm trying to
figure out what the best way of doing this would be. I am using walk
to get a list of all of the files in each directory.
I am using this code to compare the file lists:
def compare_files(first_list, second_list, first_dir, second_dir):
missing = in_first_only(first_list, second_list)
for item in missing:
index = first_list.index(item)
|
by: J.W. |
last post by:
How do I compare strings in javascript? The "==" double equals or
"!=" doesn't seem to work in this case.
I'm sure string comparison has been explained before but searching
Google didn't find any code that looked similar to this one:
-----
function CheckPassword(val,val2, str) {
var strInput = new String(val.value);
|
by: Drew |
last post by:
Hello -
I am a converted VB programmer. What I am trying to do
it compare two strings in an if statement. The problem
is that when I use string.compare it always returns a
negative 1. I have entered the same string, different
strings. The string is loaded from the results from a
dataset. The other string is loaded from a textbox.
Could someone please help me in this situation?
|
by: David zhu |
last post by:
I've got different result when comparing two strings
using "==" and string.Compare().
The two strings seems to have same value "1202002" in
the quick watch, and both have the same length 7 which I
have tried to print out by debug.writeline().
But the "==" operator results false, and string.Compare()
results true.
Somebody helps me!
|
by: Samuel R. Neff |
last post by:
Why would you cast two strings to objects to compare them? I saw code
in an MS sample on MSDN and don't get it.
if ( (object)name == (object)attr.name ) {
both "name" and "attr.name" are declared as string.
http://msdn.microsoft.com/XML/BuildingXML/XMLinNETFramework/default.aspx?pull=/library/en-us/dnxmlnet/html/XmlBkMkRead.asp
Thanks,
| |
by: balakrishnan.dinesh |
last post by:
hi frnds,
Im having two 20digit numbers, But while comparing those it
is giiving wrong ouput in javascript.
for example here is my code,
my secanrio is ,
~ If first 20 digit number is greater number than second 20 digit
number ,then it should return.
|
by: Twinkle |
last post by:
HI there
i want to compare between two strings char by char.every
strings having a word document.first string name is strFileName and
second string name is strFilename1.
i want to compare strFileName with strFileName1.if there is any mistek
or some word is missing in second string then that words should be
highlight(in sense change the color of that words) by the button click
event.
pls somebody give an idea to me.
|
by: titan nyquist |
last post by:
I wish to compare two structs via == but it does not compile. I can
overload and create my own == but am I missing something that c#
already has implemented?
~titan
|
by: Tony |
last post by:
Hello!
Below I have two different ways to test if the instance tb.Text contains the
string "Programmer"
So which one to use is it just a matter of taste ?
Or could it be some advantage to one before the other.
In a book I read they had used the second one but I prefer the first one
because it it clearer.
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |