Skip to content

Instantly share code, notes, and snippets.

@chrjorgensen
Last active August 22, 2023 14:06
Show Gist options
  • Save chrjorgensen/7e4447aa8d5ec8311840335d1f71d288 to your computer and use it in GitHub Desktop.
Save chrjorgensen/7e4447aa8d5ec8311840335d1f71d288 to your computer and use it in GitHub Desktop.
CL style example
/*------------------------------------------------------------------------------------------------*/
/* */
/* Test %SCAN and replace. */
/* */
/* Build instructions: */
/* */
/*> CRTBNDCL PGM(&FCN2/&FNR) SRCSTMF('&FP') REPLACE(&R) <*/
/* */
/*------------------------------------------------------------------------------------------------*/
pgm ( &Text )
dclprcopt text( 'Test %SCAN and replace' ) dftactgrp( *no ) actgrp( TEST )
/* Declare parameters. */
dcl &Text *char 32
/* Declare constants. */
dcl &ILLEGALS *char 2 '*?'
/* Declare variables. */
dcl &Pos *uint 2
dcl &Idx *uint 2
dcl &Illegal *char 1
chgvar &Text ( %triml( &Text ) )
/* Scan and replace illegal characters with '_'. */
dofor &Idx from( 1 ) to( %size( &ILLEGALS ) )
chgvar &Illegal ( %sst( &ILLEGALS &Idx 1 ) )
chgvar &Pos ( %scan( &Illegal &Text ) )
dowhile ( &Pos *ne 0 )
chgvar %sst( &Text &Pos 1 ) '_'
chgvar &Pos ( %scan( &Illegal &Text &Pos ) )
enddo
enddo
/* Send result. */
sndpgmmsg msgid( CPF9897 ) msgf( QCPFMSG ) msgdta( &Text ) msgtype( *comp )
endpgm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment