433
Views
4
Comments
Solved
Substring and Index
Question

Hi Team,


I need to extract string from a string, can you please guide me

e.g.  Full Name ( ALIAS )  --> ALIAS (string which is in square brackets) 

if string is  David King ( DAVIDK )  i need  DavidK

Stewart Mark ( STMARK ) i need STMARK


Thanks

2019-05-22 11-30-09
Marcelo Ferreira
Solution

Hi,

You need to do something like this 

SyntaxEditor Code Snippet

Trim(Substr(Var1,Index(Var1,"(")+1,Index(Var1,")")-Index(Var1,"(")-1))

Keep in mind this isn't protected against cases where there are no brackets on var1. you need to do those checks before.

Regards,

Marcelo

UserImage.jpg
Phani M

Marcelo Ferreira wrote:

Hi,

You need to do something like this 

SyntaxEditor Code Snippet

Trim(Substr(Var1,Index(Var1,"(")+1,Index(Var1,")")-Index(Var1,"(")-1))

Keep in mind this isn't protected against cases where there are no brackets on var1. you need to do those checks before.

Regards,

Marcelo

Thanks.. Its working


2019-08-28 11-43-22
Bruno Marques

Hi,

Another option is using the Regex_Search from Text extension.


This will return the string with brackets. You only need to remove them.

SyntaxEditor Code Snippet

Substr(Regex_Search.PatternResult,1,Length(Regex_Search.PatternResult)-2)
2026-01-26 10-25-31
Lennart Kraak
Champion

To return the string without brackets, you can use:

(?<=\(\s)(.*)(?=\s\))

Find and exclude "( ", find and include "ALIAS", and find and exclude " )"

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.