473,323 Members | 1,589 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

question on substring

How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks
Jul 21 '05 #1
12 1658


"huzz" wrote:
How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks

Jul 21 '05 #2
Hi huzz,

Well, I'm not entirely sure this is the best approach, but if you know
there is "OR " at the end you could do

String s = "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR ";
s = s.Substring(0, s.Length - "OR ".Length);
--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #3
> I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "
string s = "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR ";

if (s.EndsWith(" OR "))
{
// First argument is the start index, second argument is the number of characters.
s = s.Substring(0, s.LastIndexOf(" OR "));
}

Debug.Print(s);

// should print: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"huzz" <hu**@discussions.microsoft.com> wrote in message news:BD**********************************@microsof t.com... How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks

Jul 21 '05 #4
Hi huzz,

See my reply in the forms group.
--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #5


"huzz" wrote:
How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks


Use a combination of LastIndexOf("OR") and Substring methods of the String
class
Peek at MSDN to get more details...

Jul 21 '05 #6
Sorry about that, my news reader had a hickup and I thought for a moment I
saw your question in another group, and that I answered your question
there.

Please ignore.

--
Happy Coding!
Morten Wennevik [C# MVP]
Jul 21 '05 #7
huzz,

As alternative

String s = "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR ";
s = s.Substring(0, s.LastIndexOf("OR"));

Cor
Jul 21 '05 #8
Best way is u can use string.endtrim("or")

"huzz" wrote:
How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks

Jul 21 '05 #9
Amazing. Of all my time using .NET I've never seen that function. I looked it up.

It's called TrimEnd(params char[])

So, you can use:

s = s.TrimEnd(' ', 'O', 'r', ' ');

It's case sensitive. It may not be the best approach to hardcode the character literals. You could also do this:

s = s.TrimEnd(" Or ".ToCharArray());

or

string toTrim = " Or ";
s = s.TrimEnd(toTrim.ToCharArray());

Learn something new every day :)

There are mutliple ways of accomplishing the task at hand. The best one depends on your particular situation.
Check out the System.Text.StringBuilder class for a better way to concatinate strings for dynamic SQL queries.

--
Dave Sexton
dave@www..jwaonline..com
-----------------------------------------------------------------------
"RiteshDotNet" <Ri**********@discussions.microsoft.com> wrote in message news:13**********************************@microsof t.com...
Best way is u can use string.endtrim("or")

"huzz" wrote:
How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks

Jul 21 '05 #10
RiteshDotNet wrote:
Best way is u can use string.endtrim("or")

Well, this may easily lead to unwanted results. Imagine following situation:

string s = "blah blah or ro rrroo oorr or ";

now, if you do:

string x = s.TrimEnd(' ', 'o', 'r', ' ');

you will end up with x containing:

x == "blah blah".

This is because TrimEnd() removes _all_ occurences of the provided chars
from the end of the string - regardless of their order.
This is not necessarily problem in OP's case, however it is better to be
aware of that.
"huzz" wrote:

How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks


Michal Dabrowski
Jul 21 '05 #11
On Wed, 06 Apr 2005 11:57:31 +0200, Michal Dabrowski <sp**@jest.be> wrote:

if(str.EndsWith("OR "))
{
str = str.SubString(0, str.Length - 3);
}

RiteshDotNet wrote:
Best way is u can use string.endtrim("or")


Well, this may easily lead to unwanted results. Imagine following situation:

string s = "blah blah or ro rrroo oorr or ";

now, if you do:

string x = s.TrimEnd(' ', 'o', 'r', ' ');

you will end up with x containing:

x == "blah blah".

This is because TrimEnd() removes _all_ occurences of the provided chars
from the end of the string - regardless of their order.
This is not necessarily problem in OP's case, however it is better to be
aware of that.
"huzz" wrote:

How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks


Michal Dabrowski


Otis Mukinfus
http://www.otismukinfus.com
Jul 21 '05 #12
Otis Mukinfus wrote:
On Wed, 06 Apr 2005 11:57:31 +0200, Michal Dabrowski <sp**@jest.be> wrote:

if(str.EndsWith("OR "))
{
str = str.SubString(0, str.Length - 3);
}

That's right - I just wanted to point out, that TrimEnd() approach is
rather not appropriate here.

RiteshDotNet wrote:
Best way is u can use string.endtrim("or")


Well, this may easily lead to unwanted results. Imagine following situation:

string s = "blah blah or ro rrroo oorr or ";

now, if you do:

string x = s.TrimEnd(' ', 'o', 'r', ' ');

you will end up with x containing:

x == "blah blah".

This is because TrimEnd() removes _all_ occurences of the provided chars

from the end of the string - regardless of their order.

This is not necessarily problem in OP's case, however it is better to be
aware of that.

"huzz" wrote:

How do i get rid of the "OR " (at the end) from this string?

I have : "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR "
I want: "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' "

Many thanks


Michal Dabrowski

Otis Mukinfus
http://www.otismukinfus.com


Michal Dabrowski
Jul 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Sugapablo | last post by:
I have a column named "LIST" in a table with strings like the following: 151231-1002-02-1001 151231-1001-02-1001 151231-1002-02-1002 151231-1003-02-1001 etc.... What I'd like to do is...
1
by: Ivan Marsh | last post by:
Hello, I fat fingered my newsreader while I was trying to post this before and I don't know if it's already been posted or not. I apologise if it gets posted more than once. That said... ...
1
by: sysindex | last post by:
I am trying to find a way to dynamically retrieve the substring starting point of an nText field. My query looks something like SELECT ID,Substring(DOCTEXT,0,200) from mytable where DOCTEXT...
6
by: Steve B. | last post by:
Hello everybody In a webpage, I use JS display data from an xml file and a xsl file: var data = new ActiveXObject("Microsoft.XMLDOM"); data.async = false; var dataUrl = "data.aspx";...
5
by: Burak | last post by:
Hello, I would like to format the string "11304200" into "11-3042.00". Can I do this with String.Format method? I have not come across any good documentation. Thank you,
3
by: denis_browne | last post by:
Hi there, I got a tough interview questions lately, and I would like to hear your opinion: An array of N chars is given Write an efficient algorithm to find all the repeating substring with a ...
12
by: Paul | last post by:
Hi, I am trying to check a string to see if it's first 3 characters are numeric and if they are, to replace those 3 characters with something else. I've tried this but nothing happens... ...
12
by: =?Utf-8?B?SlA=?= | last post by:
I am a newbie to regular expressions and want to extract a number from the end of a string. The string would have these formats: image/4567 image/45678 image/456789 I would also want to...
4
by: BeSharp | last post by:
I recently stumbled across a pretty interesting LINQ to SQL question and wonder, whether anybody might have an answer. (I'm doing quite some increasing LINQ evangelism down here in Germany.). ...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
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 using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.