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.
--
GrandpaB 7 5750
Have you tried simply to do a .Replace("""",'')
Rykie,
Great suggestion! I tried .Replace as you suggested, but it did not work. I
got the same result; my puzzlement deepens. I think that I'm having a severe
attack of stupid and I'm missing something absolutely trival. Thanks for
your help.
--
GrandpaB
Man, it looks like it ought to work. The only thing I can think of is to try
trimchar() as char = {chr(34)}
--
Dennis in Houston
"GrandpaB" wrote: Rykie,
Great suggestion! I tried .Replace as you suggested, but it did not work. I got the same result; my puzzlement deepens. I think that I'm having a severe attack of stupid and I'm missing something absolutely trival. Thanks for your help. -- GrandpaB
Dennis,
Another hearty thanks, but still no cigar! This is another good suggestion,
but it hasn't gotten to the root cause of the problem. I'm bamboozled and
bleary-eyed!
With all the suggestions my code now looks like this:
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}
Dim trimChar() As Char = {Chr(34)} 'Suggestion Dennis
xTitle = CType(xArt, objArt).Title
x1Title = xTitle.TrimStart(trimChar)
'x1Title = xTitle.Replace("""", "") 'Suggestion Rykie
yTitle = Me.Title
y1Title = yTitle.TrimStart(trimChar)
'y1Title = yTitle.Replace("""", "") 'Suggestion Rykie
Return y1Title.CompareTo(x1Title)
End Function
The list of Locals produces:
x1Title "“The Following Cold”" String
xTitle "“The Following Cold”" String
y1Title "“773 Stan Drive”" String
yTitle "“773 Stan Drive”" String
--
GrandpaB
How about:
if xTitle.StartsWith("""") Then
xTitle = xTitle.Substring(1)
End If
etc etc
This worked for me too
xTitle = xTitle.TrimStart("""")
Rykie
Rykie,
Problem solved, thanks to your suggestons. This proves that VB.Net is a
rich language and there are many ways to skin a cat, but your second
suggestion provided the clue on how to skin this one.
I am using Option Stirct so I had to implement your third suggestion as:
xTitle.TrimStart(""""c)
I introduced the extra variables, x1Title and y1Title, so that I could more
easily trace the progrm. Your second suggestion then became:
If xTitle.StartsWith("""") Then
x1Title = xTitle.Substring(1)
Else
x1Title = xTitle
End If
Stepping through your second suggestion showed that the StartsWith("""")
method never evaluated to true even when the string contained a leading quote
character.
I then inserted a MsgBox to display the ASCII code of the first character.
It was not a standard quote Char(34) it was a LEFT quote Char(147)!
As I previously said I had a severe attack of stupid and it was a trivial
problem.
--
GrandpaB This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Simon |
last post by:
Hi there.
I seem to be a flurry of questions here recently, thanks for you help all,
but ... got another question here.
I am storing URL in a database for a 'sort of' directory type website.
...
|
by: Generic Usenet Account |
last post by:
I have worked out the following implementation for trimming the leading
and trailing whitespace characters of a string (I am surprised not to
see these as member functions). Am I doing it...
|
by: Stefan Weiss |
last post by:
Hi.
(this is somewhat similar to yesterday's thread about empty links)
I noticed that Tidy issues warnings whenever it encounters empty
tags, and strips those tags if cleanup was requested....
|
by: john_g83 |
last post by:
have a bit of c code that is ment to take a string (that may or may not
have spaces before or after the string) i.e. " stuff ", and trims off
the whitespace before and after.
Code:
char *trim...
|
by: brian_harris |
last post by:
I am tring to use trimstart to remove leading zeros, but all things I try
give a compiler error on converting data. I am programing in C++ .net vs2003.
This is one of my earlier attempts to call...
|
by: Paul |
last post by:
On my local site, I have a folder that is security trimmed, so that only
members of a Role can see it after they register and log on (I set the
memberships). All works fine locally.
However,...
|
by: leeps_my |
last post by:
I'm thinking of using "resize-to-size" to do the trimming:
aVector.resize( aVector.size( ) );
I'm wondering why Scott Meyers was recommending "swap trick" instead,
since the trick involves...
|
by: rmgalante |
last post by:
Hi,
I've got my site configured to use a menu control, a site map, security
trimming, and roles. Everything seems to be working, except I have the
following problem.
If I define a...
|
by: sjoshi |
last post by:
Is List.ConvertAll the only way to apply TrimStart to elements of a
List<stringor is there a better way ?
Currently I'm doing this...
List<stringlst = new List<string>();
lst.AddRange(new...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
by: taylorcarr |
last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
| |