You can translate the question and the replies:

Split a string and return the last element as a string (not an array)

Hi There, I have a string in the following format: /section1/section2/section3 I need to return only **section3** as a string. Is there a way to do this? Regards, Adam
user
15-11-2021 19:38:38 -0500
code

3 Answers

Hi, In order to separate values from texts, you can use the string function like SUBSTR,SPLIT, etc. For instance, I was able to execute the following query to get the last element as a string. `SELECT split[3].string as s1 from (select split('/','/section1/section2/section3'));` For more information, you could take a look at the ”[Text Functions](https://community.denodo.com/docs/html/browse/8.0/en/vdp/vql/functions/text_functions/text_functions)” section under Virtual DataPort VQL Guide. Hope this helps!
Denodo Team
16-11-2021 01:03:52 -0500
code
Hi Denodo team, Just got another question following up above conversition. Is there any way to reverse only the elements? For example ``` section1/section2/section3 -> section3/section2/section1 ``` Or if there is another way to extract the last element without using the forward indexing expression, i.e .using something like ``` split[-1].string ``` Out challenge is to get the last element which is at *different* position for each row. So we either reverse the string and get the first element for each row or get the last element without reversing. We tried the [-1] expression but it did not work. Could you please suggest how we can achieve this goal? Best regards, Sachin
user
28-03-2022 02:33:39 -0400
Hi, I was able to fetch the last string using the REGEXP functions. For example, you could execute the following REGEXP function in a VQL shell. > select regexp("<Column_Name>",'([a-z]+[0-9]+)+\/','') from <View_Name> For more information, have a look at the [Regexp Functions ](https://community.denodo.com/docs/html/browse/latest/en/vdp/vql/functions/text_functions/text_functions#regexp)section of Virtual Dataport VQL Guide. Hope this helps!
Denodo Team
28-03-2022 09:10:14 -0400
code
You must sign in to add an answer. If you do not have an account, you can register here