how can i get part of string into another variable of type char

695 pts.
Tags:
RPG
RPGLE
hi, i have one name field of length 60 it contains all first,last,middle names corrospondingly , in that those r seperated by '/' now i want to move those last and first and middle names to 3 separate variables of type char now i know that with %SUBST we can get part of name but my problem is i want to get first name till i encounter '/' between first and last name and last name and middle name seperately

Answer Wiki

Thanks. We'll let you know when a new response is added.

You could use the %Scan built in function to find the ‘/’ characters in the name string, and then parse the individual components accordingly. In the snippets below, assume that Start, Position and Length are decimal variables of the size you need, depending on the total length of the Name field. (I think that %Scan and %SubSt accept Integer types as well).

Then, once you know the position of the slash, you can use that to control the starting position and length of the %SubSt function to move through the string to extract the last, first, and middle names.

<pre>
/Free
// search for end of first name (starting position of scan function will default to 1 if not specified)
// Adjust ending position of substring to not include the slash
Position = %Scan(‘/’ : Name) ;
Length = Position – 1 ;
FirstName = %SubSt(Name : 1 : Length) ;

// advance starting position to search for last name – start after the position where the slash was found
Start = Position + 1 ;
Position = %Scan(‘/’ : Name: Start) ;
Length = Position – Start ;
LastName = %SubSt(Name : Start : Length) ;

// (If there is a slash after the middle name, this same method should work. If no slash, then you
// could simplify this accordingly, as you wouldn’t need to scan for the last slash and could just put the
// last part of the string into the MiddleName field.
Start = Position + 1 ;
Position = %Scan(‘/’ : Name: Start) ;
Length = Position – Start ;
MiddleName = %SubSt(Name : Start : Length) ;
/End-Free
</pre>

This is just a rough draft and I haven’t tested it, but I hope it helps you with devising a method that will work for you.

Discuss This Question: 6  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
  • BigKat
    Wow, that is the first time I ever had some one DELETE my answer and put theirs. Especially since we said the same thing, except I just explained to Mohan what he could do and left it to him to code it rather than code it for him. :-(
    8,330 pointsBadges:
    report
  • Cwc
    Your answer got deleted??? Well that must have been a glitch, because I didn't see anything there before I submitted mine. Sorry that happened.
    4,290 pointsBadges:
    report
  • BrentSheets
    BigKat, the answer section is a Wiki that encourages a collaborative effort - so members work together to build the best answer. All the contributor names are listed at the top of the answer and all efforts are appreciated. The answer probably wouldn't be so complete without your initial contribution - which was expanded on. If you ever think the answer you provided, or a part of the answer you provided, should still be part of the answer - then by all means feel free to paste it back in. And thanks again for sharing your expertise with the community.
    6,925 pointsBadges:
    report
  • BrentSheets
    I was posting my comment at the same time as Cwc and didn't see his. This illustrates the point perfectly. What probably happened was that you both had the answer open at the same time. If someone had an answer open and got a phone call or whatever, researched the answer, then posted - they never see the other response because they had the answer open for an extended time.
    6,925 pointsBadges:
    report
  • Cwc
    That must be exactly what happened, as I did have the answer open for a while and had to come back to it later to complete it. Next time, I'll know better.
    4,290 pointsBadges:
    report
  • BigKat
    Ahh, my apologies Cwc At least Mohan got his answer!
    8,330 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