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 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
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]
> 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
Hi huzz,
See my reply in the forms group.
--
Happy Coding!
Morten Wennevik [C# MVP]
"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...
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]
huzz,
As alternative
String s = "Keywords LIKE '%awlad%' OR Keywords LIKE '%huzz%' OR ";
s = s.Substring(0, s.LastIndexOf("OR"));
Cor
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
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
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
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
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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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...
...
|
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...
|
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";...
|
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,
|
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
...
|
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...
...
|
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...
|
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.).
...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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
|
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...
|
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...
| |