Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Split string and take last element

I have a table with this values:

Articles/Search/ArtMID/2681/ArticleID/2218/Diet.aspx OurStory/MeettheFoodieandtheMD.aspx TheFood/OurMenu.aspx 

I want to get this

Diet.aspx MeettheFoodieandtheMD.aspx OurMenu.aspx 

How can i do this?

like image 883
Antonio Papa Avatar asked Jan 19 '13 09:01

Antonio Papa


People also ask

How do you find the last element in a string array?

To get the last element of the array, we can pass in index -1 as the start index to return an array that has the last element of the array. We don't need the end index since the default value for the end index is the last index of the array. We use [0] to get the first element of the array returned by slice .

How do you split the last element in Python?

Use the str. rsplit() method with maxsplit set to 1 to split a string and get the last element. The rsplit() method splits from the right and will only perform a single split when maxsplit is set to 1 .

How do you split a string into elements?

Python split() method is used to split the string into chunks, and it accepts one argument called separator. A separator can be any character or a symbol. If no separators are defined, then it will split the given string and whitespace will be used by default.

Does Split () return a list?

The split() method of the string class is fairly straightforward. It splits the string, given a delimiter, and returns a list consisting of the elements split out from the string.


1 Answers

The way to do it in SQL :

SELECT SUBSTRING( string , LEN(string) -  CHARINDEX('/',REVERSE(string)) + 2  , LEN(string)  ) FROM SAMPLE; 

JSFiddle here http://sqlfiddle.com/#!3/41ead/11

like image 87
jazzytomato Avatar answered Oct 02 '22 08:10

jazzytomato