project help
project help
I am in my final semester of community college. I have to take a q-basic programming class and I am struggling very badly. I have approached the professor and he is so intelligent but he just can't seem to put it into language that I understand. Our project is to write a program that prints a first name - last name output regardless of the format it was inputted in. Ex: Input John Smith prints John Smith Input Smith, John prints John Smith. I wrote a synapsis of the problem as follows: Seperate a given string into substrings and print the first and last substring names in seperate columns. Now I am floundering. First, Is Mid$ the best function to use to seperate the substrings? Second How do I make it recognize the space or the comma as the seperators between strings? and Last How do I tell the program how to chose which substring to print first? I have read our book (Q-Basic using modular structure) and it is not very helpful. The teacher does not use it at all because he says it is worthless and I have tried google searches. I'm not asking for you to do the work, just to point me in the right direction. Thanks!! Deb
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
Hi Deb,
Basically, one thing I can tell you is that the INSTR$ function is your friend here. It is defined as:
INSTR$ returns the position where SearchFor was found in Text. It should be what you need to determine if there's a comma or a space.
Technically, the user should enter John Smith, Smith,John or maybe even Smith, John (with a space and a comma). so the first part of this should be looking for which one of the three it is.
To filter out the first and last name when they are lastname, first name you'll just need to do it with left$ and right$
hope this helps
Basically, one thing I can tell you is that the INSTR$ function is your friend here. It is defined as:
Code: Select all
INSTR$([Start,] Text, SearchFor)
Technically, the user should enter John Smith, Smith,John or maybe even Smith, John (with a space and a comma). so the first part of this should be looking for which one of the three it is.
Code: Select all
SpaceResult% = INSTR$(NameString$, " ")
CommaResult% = INSTR$(NameString$, ",")
IF SpaceResult% > 0 THEN
IF CommaSpaceResult% > 0 THEN
' this is lastname, firstName
ELSE
' this is FirstName LastName, just print it as is
END IF
ELSE
' LastName,FirstName (no space)
END IF
hope this helps

When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
project help
Mystik, Thank you very much that was very helpful and wonder of wonders I am relatively sure that I understood your explanation. Do you want to teach the rest of my class? Oh well it was worth a shot. I do have one question for you though. When I use INSTR$ to search for the space how would I handle it if it found more than one occurence, such as if the person used a middle name or middle initial? I don't want to print them. Thanks again. Deb
-
- Veteran
- Posts: 703
- Joined: Sun Nov 14, 2004 7:36 am
- Contact:
Let's assume the following:
Name1String$ = "Garcello, Marcel R."
Name2String$ = "Leana R. Jackson"
Hence one needs to be inverted and the other does not.
As I mentionned INSTR$'s first parameter is where to start the search from in the string. So, you'd need 2 Position variable, let's call them:
In the case of name1String$:
FirstSpace1% should be 9
SecondSpace1% should be 17
In the case of name2String$:
FirstSpace2% should be 5
SecondSpace2% should be 8
Now since Name1String$ should be inverted since the last name is first you just need to get the following.
In the case of Name2String$ which doesn't need to be inverted you just get everything before FirstSpace2% and everything after SecondSpace2% like so:
Then you just print those 2 variables:
And there you have it. I can't quite teach you the rest of the course since I don't have the teacher's program at hand
. But if you have more questions, do feel free to ask
.
Hope this helps
Name1String$ = "Garcello, Marcel R."
Name2String$ = "Leana R. Jackson"
Hence one needs to be inverted and the other does not.
As I mentionned INSTR$'s first parameter is where to start the search from in the string. So, you'd need 2 Position variable, let's call them:
Code: Select all
FirstSpace1% = INSTR$(Name1String$, " ")
SecondPlace1% = INSTR$(FirstSpace1% + 1, Name1String$, " ")
FirstSpace2% = INSTR$(Name2String$, " ")
SecondPlace2% = INSTR$(FirstSpace2% + 1, Name2String$, " ")
FirstSpace1% should be 9
SecondSpace1% should be 17
In the case of name2String$:
FirstSpace2% should be 5
SecondSpace2% should be 8
Now since Name1String$ should be inverted since the last name is first you just need to get the following.
Code: Select all
' Beware of linewraps in this window..should be 2 lines only, not 3 that you might see.
LastName$ = LEFT$(Name1String$, FirstSpace1% - 1)
' FirstName is what's between your two found positions, + 2 for the ", "
FirstName$ = MID$(Name1String$, FirstSpace1% + 2, SecondSpace1%-FirstSpace1% + 1)
Code: Select all
' Beware of linewraps in this window..should be 2 lines only, not 3 that you might see.
FirstName$ = LEFT$(Name2String$, FirstSpace2% - 1)
LastName$ = RIGHT$(Name2String$, LEN(Name2String$) - SecondSpace2% + 1)
Code: Select all
PRINT FirstName$; " "; LastName$


Hope this helps
When God created light, so too was born, the first Shadow!
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
MystikShadows
Need hosting? http://www.jc-hosting.net
Interested in Text & ASCII development? Look no further!
http://www.ascii-world.com
project reply
