How do I trim a character off of a string if and only if it exists, once it's in a variable?


I assign a string to a variable, from a qry, and if per chance the string contains the letter T, I want to strip that T off.  Is it possible?

Here is the code where it happens

Public Sub GetRaceResults(ByVal dsnHistory)

            Dim DriverFirstName As String
            Dim DriverLastName As String
            Dim CarNumber As String
            Dim RaceRank As Integer
            Dim Team As String

            Dim data As New DataSet
            Dim r As DataRow
            Dim con As New SqlClient.SqlConnection(dsnHistory)

           data = New DataSet

            Dim dr As SqlClient.SqlDataReader

            con = New SqlClient.SqlConnection(dsnHistory)


            Dim c As New SqlClient.SqlCommand("SELECT " _
            & "DriverFirstName=RTrim(FirstName), " _
            & "DriverLastName=RTrim(LastName), " _
            & "CarNumber=RTrim([No]), " _
            & "RaceRank, " _
            & "Team=Rtrim(Team), " _
            & "License " _
            & "FROM " _
            & "Results " _
            & "WHERE (SeasonID = " & SeasonID & " AND EventID = " & EventID & "AND RunID = " & RunID & ")" _
            & "ORDER BY RaceRank", con)

            dr = c.ExecuteReader(CommandBehavior.SingleResult)

           'loop through the records
            While dr.Read()

                'assign DriverFirstName to variable
                DriverFirstName = dr.Item("DriverFirstName")
                'assign DriverLastName to variable
                DriverLastName = dr.Item("DriverLastName")
                CarNumber = dr.Item("CarNumber") <--If at this point, the string inside has a T on the end, can I kill that T?
                'assign RaceRank to variable
                RaceRank = dr.Item("RaceRank")
                'assign Team to variable
                Team = dr.Item("Team")


Thanks in advance!
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jeff CertainCommented:
does it matter where in the string the letter T appears?
CarNumber = CarNumber.TrimEnd("T"c)

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
indy500fanAuthor Commented:
I think amit_g's close.  

Now, if there isn't a T on the end, will the code fail?

Let's say in scenario 1, CarNumber = "4T", amit_g's code should work.  But, if in scenario 2, CarNumber = "4", will there be any problems with:

CarNumber = CarNumber.TrimEnd("T"c)

It would not do anything. So $T would end up being 4 and 4 would also end up being 4.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.