Can I convert single characters into integers in RPGLE?

344875 pts.
Tags:
Integer
RPGLE
I'm looking for a way to convert single characters in RPGLE into integers. It would have to work for all inputs and provide a different integer for each input (or at the very least provide a different value for all common inputs). This is a sample code of how I would like it to work:
characterData = "Hello";
for i = 1 to %len(string);
    singleCharacter = %subst(characterData:i:1);
    number = myFunction(singleCharacter);
    dsply 'The value of ' + singleCharacter + ' is ' + %char(number);
endfor;
Which would print:
The value of H is 72
The value of e is 101
The value of l is 108
The value of l is 108
The value of o is 111
I'm not as interesting in the numbers, just so they are different for each input. Thanks for all the help!

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: 2  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
  • ToddN2000

    Why not have a translation table and look up the values? A=1, B=2, C=3.....

    OR even easier you can use the ASCII value of the Char.

    Dim i As Integer = Asc("x") '
    9,700 pointsBadges:
    report
  • TomLiotta
    Since RPG doesn't have an ASC() function, it won't help much. The simplest way is probably to redefine the single character byte as a 1-byte unsigned integer, i.e., [3u 0]. No function necessary. The 'conversion' happens simply because the memory is referenced through a different definition. But it's not the kind of thing RPG is used for. It'd likely be better simply to code it in C since it makes more sense in C. -- Tom
    125,585 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