Using SUBSTR() AND INSTR() find end of string

8.7k views Asked by At

I have a problem, to select a substring from a string. The string after equal. My example looks like this one.

string='test = 1234sg654'

My idea was to select the string after the equal "1234sg654", in this way: with Instr() find position of equal, after that with Substr(), subtract the string after equal until end of string.

equal=INSTR(string,'=',1,1);
aux=Substr(string,-1,equal); // -1 I thought that is represent end of line

But the result is not 1234sg654 Where is my mistake?

1

There are 1 answers

0
Gordon Linoff On BEST ANSWER

Don't use -1 for the position argument -- the substring starts that many characters from the end of the string. You can just do:

aux = substr(string, instr(string, '=') + 1)

No third argument means "go to the end of the string".