ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

strip single from the ends of a string

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • strip single from the ends of a string

    Is there a way to remove the beginning and ending single quote from a text string that is to be used in a parameter.
    I place information into a *char variable and it is enclosed in quotes. The command I use, cpysplf doesn't like the quotes.

    cpysplf file(ODI860P) tofile(*TOSTMF) job(&splinfo) +
    tostmf(&filnme) wscst(*PDF)

    &splinfo is input from another program and I do not know what it is at the time the CL is run.

  • #2
    Re: strip single from the ends of a string

    Just something I through together quick, probably a better way. NEWPATH comes out as TEST instead of 'TEST'

    Code:
    PGM
                 DCL        VAR(&PATH) TYPE(*CHAR) LEN(10) VALUE('''TEST''')
                 DCL        VAR(&CHAR) TYPE(*CHAR) LEN(1) VALUE('''')
                 DCL        VAR(&NEWPATH) TYPE(*CHAR) LEN(10)
                 DCL        VAR(&START) TYPE(*UINT) LEN(2)
                 DCL        VAR(&END) TYPE(*DEC) LEN(2)
                 CHGVAR     VAR(&START) VALUE(%SCAN(&CHAR &PATH))
                 CHGVAR     VAR(&START) VALUE(&START + 1)
                 CHGVAR     VAR(&END) VALUE(%SCAN(&CHAR &PATH &START))
                 CHGVAR     VAR(&END) VALUE(&END - &START)
                 CHGVAR     VAR(&NEWPATH) VALUE(%SUBSTRING(&PATH &START &END))
                 ENDPGM

    Comment


    • #3
      Re: strip single from the ends of a string

      The built-in-Function %TRIM should do the job;

      Code:
      DCL VAR(&SplfINfo)    TYPE(*CHAR) LEN(30)  
      DCL VAR(&Quote)       TYPE(*CHAR) LEN(1) VALUE('''') 
      CHGVAR VAR(&SplfInfo) VALUE(%TRIM(%TRIM(&SplfInfo) &Quote))
      Birgitta

      Comment

      Working...
      X