695 pts.
 how can i get part of string into another variable of type char
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

Software/Hardware used:
ASKED: July 9, 2008  11:11 AM
UPDATED: July 11, 2008  2:02 PM

Answer Wiki:
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.
Last Wiki Answer Submitted:  July 9, 2008  2:41 pm  by  BigKat   7,205 pts.
All Answer Wiki Contributors:  BigKat   7,205 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

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.
:-(

 7,205 pts.

 

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,275 pts.

 

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,580 pts.

 

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,580 pts.

 

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,275 pts.

 

Ahh, my apologies Cwc
At least Mohan got his answer!

 7,205 pts.