G
Guest
I am comparing two strings for sorting. In some cases the string may be
enclosed in quotes. Since the quote character is less than the A character,
all the strings enclosed in quotes will finish the sort ahead of all other
strings. My function first attempts to strip the leading quote character, if
it exists, from the string.
Code:
Public Function CompareTo(ByVal xArt As Object) As Integer _
Implements System.IComparable.CompareTo
'some Titles are enclosed in quotes; remove the quotes to sort
Dim xTitle As String
Dim x1Title As String
Dim yTitle As String
Dim y1Title As String
Dim trimChar() As Char = {""""c}
xTitle = CType(xArt, objArt).Title
x1Title = xTitle.TrimStart(trimChar)
yTitle = Me.Title
y1Title = yTitle.TrimStart(trimChar)
Return y1Title.CompareTo(x1Title)
End Function
I have added some dummy variables so that I could watch the TrimStart
process. xTitle and yTitle contain the pre-trimmed strings. x1Title and
y1Title should be the trimmed strings. However if xTitle = """Pansies"""
x1Title = """"Pansies""" The yTitle and y1Title variables have the same
problem!
I have created a short test program to trim quote characters; it works, but
something silly is eluding me in this function. Can you fine my error?
Thanks for your assistance.
enclosed in quotes. Since the quote character is less than the A character,
all the strings enclosed in quotes will finish the sort ahead of all other
strings. My function first attempts to strip the leading quote character, if
it exists, from the string.
Code:
Public Function CompareTo(ByVal xArt As Object) As Integer _
Implements System.IComparable.CompareTo
'some Titles are enclosed in quotes; remove the quotes to sort
Dim xTitle As String
Dim x1Title As String
Dim yTitle As String
Dim y1Title As String
Dim trimChar() As Char = {""""c}
xTitle = CType(xArt, objArt).Title
x1Title = xTitle.TrimStart(trimChar)
yTitle = Me.Title
y1Title = yTitle.TrimStart(trimChar)
Return y1Title.CompareTo(x1Title)
End Function
I have added some dummy variables so that I could watch the TrimStart
process. xTitle and yTitle contain the pre-trimmed strings. x1Title and
y1Title should be the trimmed strings. However if xTitle = """Pansies"""
x1Title = """"Pansies""" The yTitle and y1Title variables have the same
problem!
I have created a short test program to trim quote characters; it works, but
something silly is eluding me in this function. Can you fine my error?
Thanks for your assistance.