473,394 Members | 1,703 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,394 software developers and data experts.

get the right side of string ?

Anyone have a one liner of code to getting the right side of a string after
the last occurence of a given character?
Thanks, Bill

ie '*abc*def*ghi' would yield '*ghi' (or 'ghi' would be acceptable)

Nov 12 '05 #1
3 9650
Language SQL, in a stored proc.

"Bill Smith" <x@x.com> wrote in message
news:58********************@fe2.columbus.rr.com...
Anyone have a one liner of code to getting the right side of a string
after the last occurence of a given character?
Thanks, Bill

ie '*abc*def*ghi' would yield '*ghi' (or 'ghi' would be acceptable)

Nov 12 '05 #2
Bill Smith wrote:
Anyone have a one liner of code to getting the right side of a string after
the last occurence of a given character?
Thanks, Bill

ie '*abc*def*ghi' would yield '*ghi' (or 'ghi' would be acceptable)


The following function will. Note that the output is limited to 50
bytes. If you need a possible longer output, you'll have to change it
accordingly. Invoke the function by passing it the arguments.

Phil Sherman
drop function posstrl!

create function posstrl (haystack varchar(4000), needle char(1))
returns varchar(50) deterministic no external action
contains sql
begin atomic
declare i1 int;
declare i2 int;
set i1 = locate(needle,haystack);
while i1 > 0 do
set i2 = i1;
set i1 = locate(needle,haystack,i1+1);
end while;
return rtrim(right(haystack,(length(haystack)-i2)));
end!

Nov 12 '05 #3
Thanks Philip,
I was hoping to get rid of the looping. I had a similar while loop using
the RIGHT and LENGTH functions, but yours is more efficient using LOCATE.
Thanks,
Bill
"Philip Sherman" <ps******@ameritech.net> wrote in message
news:WN******************@newssvr31.news.prodigy.c om...
Bill Smith wrote:
Anyone have a one liner of code to getting the right side of a string
after the last occurence of a given character?
Thanks, Bill

ie '*abc*def*ghi' would yield '*ghi' (or 'ghi' would be acceptable)


The following function will. Note that the output is limited to 50 bytes.
If you need a possible longer output, you'll have to change it
accordingly. Invoke the function by passing it the arguments.

Phil Sherman
drop function posstrl!

create function posstrl (haystack varchar(4000), needle char(1))
returns varchar(50) deterministic no external action
contains sql
begin atomic
declare i1 int;
declare i2 int;
set i1 = locate(needle,haystack);
while i1 > 0 do
set i2 = i1;
set i1 = locate(needle,haystack,i1+1);
end while;
return rtrim(right(haystack,(length(haystack)-i2)));
end!

Nov 12 '05 #4

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

Similar topics

1
by: Anton | last post by:
Hello ! I am writing a small program and wondering whether this expression is right? std::list< std::string > strList I mean that this is container into container and don't know the side...
1
by: Norman Fritag | last post by:
Hi there I was wonder how I can synchronise left page ( title) of a frame with relevant hypertext ( to be highlighted) on the right side?? Right side Page contains only a hieratical list of...
22
by: Marek Mand | last post by:
How to create a functional *flexible* UL-menu list <div> <ul> <li><a href=""></li> <li><a href=""></li> <li><a href=""></li> </ul> </div> (working in IE, Mozilla1.6, Opera7 (or maybe even...
1
by: cheezebeetle | last post by:
ok, so I am having problems passing in an ASPX function into the Javascript in the codebehind page. I am simply using a confirm call which when they press "OK" they call this ASPX function, when...
9
by: Durgesh Sharma | last post by:
Hi All, Pleas help me .I am a starter as far as C Language is concerned . How can i Right Trim all the white spaces of a very long (2000 chars) Charecter string ( from the Right Side ) ? or how...
1
by: G.Esmeijer | last post by:
Friends, I'm (a bit) dissapointed about the printing possibilities in c#. It could also be lack of knowedge. I would like to align a text on the right side of the paper when printing. For...
7
by: jtfaulk | last post by:
I need to encode some information on the server side using ASP.NET with C#; sending via HTTP to a client side application, that needs to be decoded in an MFC C++ application. I'm not sure if I...
2
by: garyusenet | last post by:
I could do with something similiar, can you tell me if you think this would work for me, and if there's any advantage in working with controls this way than how I currently am. At the moment...
1
by: Max2006 | last post by:
Hi, To protect my WCF service boundaries, I assign a unique support ticket to all server side exceptions, log them and send a general FaultException to client that only include the support...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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?
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
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.