TrimEnd

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
Peter NordbergIT ManagerAsked:
Who is Participating?
 
Ashley BryantConnect With a Mentor Senior Software EngineerCommented:
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
 
Type25Commented:
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
 
Type25Connect With a Mentor Commented:
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
 
Peter NordbergIT ManagerAuthor Commented:
Thanks! Both scripts did what I wanted!

Peter
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.