473,396 Members | 2,055 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,396 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 1662


"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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.