2

I understand that the string_variable(start:length) can be used to get a substring of a string given a starting point and substring length, however, I am finding that I often need to get a substring between a 'start' and 'end' point.

While I know I could always do this:

SUBTRACT start FROM end GIVING len
string(start:len)

It seems cumbersome to have to do so every time when I am writing programs that use this functionality often. Is there perhaps a quicker/built-in way of achieving this?

Matt Haidet
  • 338
  • 3
  • 14

1 Answers1

7

How about?

    move str (start-pos : end-pos - start-pos + 1) to ...

You can subtract the first from the last, but you need to add 1 to get the correct length.

STRING is a statement name, as is START, and END is reserved. LENGTH is a function name. I avoid those in anything that looks like code.

Rick Smith
  • 3,962
  • 6
  • 13
  • 24
  • 2
    Just to add for @matt-haidet: You can also simply drop the `len` if you want the complete rest of the field. If you use a current compiler (which I assume as you've added the gnucobol tag ;-) then you can also create a user-defined function which takes those three parameters (maybe the len as optional) and returns the result back... – Simon Sobisch Feb 15 '19 at 19:16