Use of substr() function in AX 2009

Hi,

I wanted to get “157050” from the string “J/157050/0001” using subStr() in AX 2009.

Regards,

/Ashlesh

substr(“J/157050/0001”,3,6);

Hi,

Thanks for the reply. But it will not help me.

I dont want hard code anything. By using “3” and “6” we are going to hardcode the position and length.

Regards,

/Ashlesh

Hi Ashlesh,

To get the length, you can use strlen() function.

But if you wish to use subStr() function, you have to let the system know -

  1. Starting position and
  2. Number of characters.

If you don’t want to hard code, then you can parameter these two values.

Best wishes,

Hi Ashlesh,

You can also try using ‘TextBuffer’ class. An example from Developers guide -


int pos;
TextBuffer textBuffer;
;

textBuffer = new TextBuffer();
textBuffer.setText(“ABC DEF GHI JKL MNO ABC ABC”);
pos = 0;

while (textBuffer.find(“ABC”,pos))
{
print "String found at position: ", textBuffer.matchPos();
pause;
pos = textBuffer.matchPos()+1;
}


Best wishes,