Author Topic: Find a string between two symbols  (Read 139 times)

Offline sunily

  • Full Member
  • ***
  • Join Date: Oct 2013
  • Posts: 15
  • Forum Citizenship: +0/-0
Find a string between two symbols
« on: 13 Jul 2018 04:30:55 am »
Hi,

I know this is a noob question and might be asked few times in this forum.

I want to extract a string between two symbols.

For eg: A_B_C_D

I want to extract B from this. There might be less or more _ in string and length of A,B,C,D is not fixed.

Offline BigChris

  • Statesman
  • ******
  • Join Date: Apr 2013
  • Posts: 1,112
  • Forum Citizenship: +84/-0
Re: Find a string between two symbols
« Reply #1 on: 13 Jul 2018 05:00:28 am »
For the sake of clarification, are you looking for the first _ and the character(s) between that and the next _ ?

Offline sunily

  • Full Member
  • ***
  • Join Date: Oct 2013
  • Posts: 15
  • Forum Citizenship: +0/-0
Re: Find a string between two symbols
« Reply #2 on: 13 Jul 2018 05:22:31 am »
Yes Chris, you got it right.

Offline sunily

  • Full Member
  • ***
  • Join Date: Oct 2013
  • Posts: 15
  • Forum Citizenship: +0/-0
Re: Find a string between two symbols
« Reply #3 on: 13 Jul 2018 05:51:39 am »
Looks like I got it:

 substring_index(substr(zoneName, locate('_',zoneName)+1,locate('_',zoneName)-1),'_',1)

Please validate or suggest better way
« Last Edit: 13 Jul 2018 06:03:51 am by sunily »

Online sdf

  • Statesman
  • ******
  • Join Date: Feb 2014
  • Posts: 440
  • Forum Citizenship: +3/-0
Re: Find a string between two symbols
« Reply #4 on: 13 Jul 2018 08:09:27 pm »
are you always gonna get the 3rd string?

is substring([zoneName],3,0)

an option?

 


       
Twittear