get value between ( and )

User avatar
sal21
PlatinumLounger
Posts: 4576
Joined: 26 Apr 2010, 17:36

get value between ( and )

Post by sal21 »

i just have myvar="61-DE RUBERTIS GIOVANNI-(14/05/1989)-(INS)"

How to get the value from the last ( and )?

In my case INS, and assign the current value to myvar1

Note:
The internal of ( and ) are only 2 value MOD and INS
Naturally the lenght of myvar is variable

User avatar
HansV
Administrator
Posts: 80088
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: get value between ( and )

Post by HansV »

Left(Right(myvar, 4), 3)
Best wishes,
Hans

User avatar
p45cal
2StarLounger
Posts: 176
Joined: 11 Jun 2012, 20:37

Re: get value between ( and )

Post by p45cal »

Do you have InStrRev in vb?
In case the last set of parentheses is not exactly at the end of the string:

myvar = "61-DE RUBERTIS GIOVANNI-(14/05/1989)-(INS)"
x = InStrRev(myvar, "(") + 1
y = InStrRev(myvar, ")")
myvar1 = Mid(myvar, x, y - x)

or shorter:
myvar = "61-DE RUBERTIS GIOVANNI-(14/05/1989)-(INS)"
x = InStrRev(myvar, "(") + 1
myvar1 = Mid(myvar, x, InStrRev(myvar, ")") - x)

User avatar
SpeakEasy
5StarLounger
Posts: 742
Joined: 27 Jun 2021, 10:46

Re: get value between ( and )

Post by SpeakEasy »

Or

Mid(myvar, Len(myvar) - 3, 3)

There is more than one way to skin a cat ... :-)