ibmi-brunch-learn

Announcement

Collapse
No announcement yet.

Padded with nulls

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

  • Padded with nulls

    The %trim(string) built-in usually gives me what I want. But sometimes 'string' is padded with nulls. How can I know when the use %trim(string:x'00')?

  • #2
    Simple answer is you can't unless you have some other "flag" that will tell you which to use.

    But there's no reason you can't use both. You said %Trim but I assume since you were talking about padding that you meant %TrimR. This code appears to do what you want.

    Code:
    dcl-s string char(20) inz('ABCDEFGHI');
    dcl-s newString varchar(20) inz;
    dcl-c trimChars x'0040';
    %subst(string: 16) = *allX'00';  // set last 5 chars to null following blanks
    newString = %TrimR(string: trimChars);
    Dsply ( newString + ' is ' + %Char(%Len(newString)) + ' long');

    Comment

    Working...
    X