?
Solved

TrimEnd

Posted on 2007-10-16
4
Medium Priority
?
601 Views
Last Modified: 2011-08-18
Hi,

I have this string:
SELECT * FROM image_descr WHERE keywords LIKE '% linda%' AND keywords LIKE '%2007%' AND keywords LIKE '%

I would like to trim the end so that the last part gets trimmed away:
AND keywords LIKE '%

I've tried the following:
Dim strParse As String = strSearch.TrimEnd("%", "'", "LIKE", "keywords", "AND")

Unforunately it only trims the last part like this:
SELECT * FROM image_descr WHERE keywords LIKE '% linda%' AND keywords LIKE '%2007%' AND keywords LIKE

How can I get it to trim away the rest?

Thanks for help!

Peter
0
Comment
Question by:peternordberg
  • 2
4 Comments
 
LVL 9

Expert Comment

by:Type25
ID: 20086169
string s = @"SELECT * FROM image_descr WHERE keywords LIKE '% linda%' AND keywords LIKE '%2007%' AND keywords LIKE '%";

            int i = s.LastIndexOf("AND");
            string x = s.Substring(0, i);

            MessageBox.Show(x);
0
 
LVL 12

Accepted Solution

by:
Ashley Bryant earned 500 total points
ID: 20086177
Dim strParse As String = strSearch.SubString(0,strSearch.Length - 21)

Assuming I understand your question correctly, you just need to lop off those last 21 characters.  That's what the above would do.
0
 
LVL 9

Assisted Solution

by:Type25
Type25 earned 500 total points
ID: 20086180
or in vb

Dim s As String =  "SELECT * FROM image_descr WHERE keywords LIKE '% linda%' AND keywords LIKE '%2007%' AND keywords LIKE '%"
 
            Dim i As Integer =  s.LastIndexOf("AND")
            Dim x As String =  s.Substring(0,i)
 
            MessageBox.Show(x)
0
 

Author Comment

by:peternordberg
ID: 20087636
Thanks! Both scripts did what I wanted!

Peter
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month14 days, 7 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question