Trailing the blanks which come in the middle of a string

335 pts.
Tags:
AS/400
RPGLE
Could anyone please let me know how I can trail the blanks that come in the middle of a string? For example, a field contains a name like 'hello hai' I want to trim the blank which came in the middle of hello and hai. Please help me with a piece of sample code.

Software/Hardware used:
iseries

Answer Wiki

Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Discuss This Question: 5  Replies

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • TomLiotta
    To clarify, assume a 15 character field containing 'hellobhaibbbbbb' where each "b" stands for a blank. You want to cause the value to become 'hellohaibbbbbbb'. . Is that correct? . What OS version are you needing this to run on? . Tom
    125,585 pointsBadges:
    report
  • JSDHFKJHA
    u got me correct.so,the string which u assumed is hellobhaibbbbbb and i want to trail the first 'b' which means blank thyat comes in the position '6' the os version whichg we r using is v7r1
    335 pointsBadges:
    report
  • CharlieBrowne
    Use the %Scan instruction to find the blanks. Then use %Substr to adjust the characters in the field
    41,370 pointsBadges:
    report
  • TomLiotta
    The obvious easy way is simply to run [ EVAL MyString = %SUBST(MyString:1:5) + %SUBST(MyString:7:3) ]. But that seems too simple. You must be asking for more than that. Do you need a general routine to compress blanks out of any value in the string variable? . The EVAL statement is the basis of any routine. If you use variables in place of the constant digits, you can run that statement in a DO-loop. Set the variables to appropriate values each time through the loop. . Use %SCAN or %CHECK to locate the position of any embedded blank. Use the %TRIM functions when you want substrings that have leading or trailing blanks removed. Use %LEN to find lengths of substrings. . Run the DO-loop until no embedded blanks remain. That will handle cases when there is more than just a single blank in the original string. . Tom
    125,585 pointsBadges:
    report
  • bvining
    As you are on 7.1 just use the new %scanrpl built-in: h dftactgrp(*no) d SomeField s 20a inz('Hello Hai') /free SomeField = %scanrpl(' ' :'' :SomeField); dsply SomeField; *inlr = *on; return; /end-free
    6,465 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following