Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trim string 1

Status
Not open for further replies.

hamking01

Programmer
May 30, 2004
238
US
I'm trying to trim a string that will always end with "AND " and trim this portion off. The string length will be vary time to time so I can't use ltrim. Is there a way for me to do this?

 
Try this theory...

C#
strItem.Substring(1,strItem.Length-4);

VB.Net
strSQL.Substring(1, strSQL.Length - 4)

Hope this helps.

Hope everyone is having a great day!

Thanks - Jennifer
 
You can also use String.TrimEnd:
Code:
   ' VB.NET
   Dim arr As String() = {"AND "}
   sSQL = sSQL.TrimEnd(arr)

   // C#
   string[] arr = {"AND "};
   sSQL = sSQL.TrimEnd(arr);

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Correct me if I'm wrong, Chip, but I believe TrimEnd() accepts a characater array and removes every instance of all characters.

I don't believe the function will work for this circumstance (and least not without removing all legitimate a's, n's and d's from the end).

[COLOR=blue gainsboro]
Get a FREE iPod by helping me get mine! Click my referrer link:

More about the company and deal:
[/color]
 
You are correct -- I didn't read the documentation closely enough. If you look at the sample code, they use a string array, but they're passing null to .TrimEnd, which just removes whitespace.

Good catch.

Chip H.


____________________________________________________________________
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top