Download presentation
Presentation is loading. Please wait.
Published byEjnar Tobias Henningsen Modified over 5 years ago
1
Please use speaker notes for additional information!
Name Flip Notes Please use speaker notes for additional information! This slide show will cover character manipulation to flip a name that is in the format last/first mid to first mid last. In this course we will flip the name using individual character access and using functions.
2
Name Flip This presentation will deal with the logic to flip a name that comes in with the format last/first mid: Johnson/Alice Mary Daniels/Stephen Ames/Jennifer A Hersey/Carl M Madison/John Lee Andrews So that it will appear as first mid last: Alice Mary Johnson Stephen Daniels Jennifer A Ames Carl M Hersey John Lee Andrews Madison Looking at what you need to do this: You need to be able to access characters individually so you can manipulate them You need to know the location of the / You need to know where the first name + middle name or initials end You need to use this information to flip the name (details follow) First we will discuss doing this through character by character manipulation. In another slide we will discuss using functions.
3
Example: Johnson/Alice Mary
Flip Name - using character manipulation with a minimum of commands/functions Example: Johnson/Alice Mary You need to be able to access characters individually so you can manipulate them Accessing characters individually usually means defining them in a table/array so that you can access each character individually. You need to know the location of the / You need to locate the / by some kind of counting technique. This can involve inspecting each character and if it is not a slash adding one to a count or using a command that can locate a certain character. You need to know where the first name + middle name or initials end The name field is a specified length, but the name may not use the entire field. You need to find how many characters the name actually uses - in other words where the first name ends if there is no middle name or middle initial or where the middle name or middle initial ends if there is one. This can be done by starting at the last character and moving backwards looking for the first non space. Most languages also have a command that can return this information. For example, in COBOL you could define the name and then redefine it as a table. The thing that occurs would be a single character and it the occurs would contain the number of characters in the field. In COBOL there is an Inspect verb that allows you to locate a particular character in a string. Other languages have similiar commands. In most languages there is some kind of length function that will return this information.
4
First, locate the slash: for this example, SLSHLOC = 8
Flip Name Example: Johnson/Alice Mary (I have assumed that the input field is 25 characters for this example) Define so that you have access to individual characters: NCH(index/subscript/pointer) points to an individual character in this example NCH(1) NCH(6) NCH(2) NCH(7) NCH(3) NCH(8) NCH(4) NCH(9) NCH(5) NCH(10) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | First, locate the slash: for this example, SLSHLOC = 8 This process will vary depending on the language you choose. To do this example, you must choose a lanaguage that allows individual access to characters. The next example will be done with functions, to do this example you must choose a language that has the functions to support this manipulation. Second, locate the last character of the name: for this example, LASTLOC = 18
5
INITIALIZE: PTIN = SLASHLOC +1 = 9 PTOUT = 1
Flip Name SLSHLOC = 8 LASTLOC = 18 INITIALIZE: PTIN = SLASHLOC +1 = 9 PTOUT = 1 Input area: Characters called NCH J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | NCH (PTIN) FCH(PTOUT) | | | | | | | | | | | | | | | | | | | | | | | | This shows the information that is needed to initialize before the loop to move the characters of the first name plus middle name (if there) to the output area. Note that this loop will terminate when the character in the LASTLOC has been moved. The control of the loop is therefore a comparison between the value of PTIN and the value in LASTLOC. Output area: Characters called FCH
6
INITIALIZE: PTIN = SLASHLOC +1 = 9 PTOUT = 1
Flip Name SLSHLOC = 8 LASTLOC = 18 INITIALIZE: PTIN = SLASHLOC +1 = 9 PTOUT = 1 Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | | | | | | | | | | | | | | | | | | | | | | | | SLSHLOC is the location of the slash LASTLOC is the location of the last character PTIN is the pointer pointing to the character to be moved (it is initialized to point to the first character of the first name) PTOUT is the pointer pointing to the character to move to in the output area (it is initialized to point to the first character of the output area) NCH is the name of the individual character in the input area (the name to be flipped) FCH is the name of the individual character in the output or flipped area (the name after it is flipped) Note that the moving or assigning of the input character to the output character and the subsequent incrementing of the subscript/index/pointer should be done in a loop. The loop should end when the last character of the first + middle name has been moved. This is why we need LASTLOC. Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT
7
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | | | | | | | | | | | | | | | | | | | | | | | Moving the second character of the first name. Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT
8
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | | | | | | | | | | | | | | | | | | | | | | You are now looping moving the next character in the input to the next character in the output. The loop will terminate when PTIN indicates that the last character of the first + middle has been moved. Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT
9
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | | | | | | | | | | | | | | | | | | | | | The loop processing is simply to move the character, increment the index/subscript/pointer. Whether the loop continues or not is dependent on whether the last character has been moved. LASTLOC is the field to compare against to make that determination. Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT
10
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | | | | | | | | | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT I have now moved the entire first name.
11
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | | | | | | | | | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT This moved the space between Alice and Mary. To preserve the integrity of the name, the space must be moved.
12
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | | | | | | | | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT This is now moving the first character of the middle name which is the fifteenth character to the seventh slot on the output.
13
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | | | | | | | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT Another move - the loop continues because the last character has not been moved.
14
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | | | | | | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT Another iteration of the loop.
15
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | y | | | | | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT At this point, when PTIN is incremented by 1 it equals 19 and 19 is greater than LASTLOC which is 18 so the loop ends. I am assuming that the testing of whether to do another iteration of the loop comes after PTIN and PTOUT have been incremented so I am doing a greater than comparison. If the test is done on the data prior to incrementing, then you would be testing for equality between PTIN and LASTLOC.
16
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name The last character of the first + middle has been moved. We know this because PTIN which contains 19 is greater than then LASTLOC which contained 18. This means resetting must be done and a new loop to move the last name will be started. Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Moving of the last name means that you want to start moving with the first character of the input. You want to skip a space and then start moving the last name to the next character of the output. A | l | i | c | e | | M | a | r | y | | | | | | | | | | | | | | | The next step is to prepare for the next loop by resetting the index/subscript/pointers. You now want to point to the first character of the input which contains the first character of the first name so you reset PTIN to 1. You now want to point to skip a space and point to the next character of the output so you increment PTOUT by 1. (Note if you had not already added to PTOUT, you would increment by 2) Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT
17
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | y | | J | | | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT You are now in a loop that will move the last name to the output one character at a time. This loop will terminate when you have moved the last character of the last name. It can be checked by comparing to the location of the slash since the slash is immediately after the last character of the last name. Remember, the location of the slash is in SLSHLOC and for this particular example it is 8.
18
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | y | | J | o | | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT The second character of the last name is moved.
19
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | y | | J | o | h | | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT The third character of the last name is moved.
20
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | y | | J | o | h | n | | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT The fourth character of the last name is moved.
21
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | y | | J | o | h | n | s | | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT The fifth character of the last name is moved. Remember this loop continues until the last name has been entirely moved. SLSHLOC is the comparison point to determine that it is complete.
22
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | y | | J | o | h | n | s | o | | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT The sixth character of the last name is moved.
23
Input area: Characters called NCH Individual characters NCH(PTIN)
Flip Name PTIN PTOUT Input area: Characters called NCH Individual characters NCH(PTIN) J | o | h | n | s | o | n | / | A | l| i | c | e | | M | a | r | y | | | | | | | Move the input character to the receiving area in the output. Then increment PTIN and PTOUT by 1. A | l | i | c | e | | M | a | r | y | | J | o | h | n | s | o | n | | | | | | | Output area: Characters called FCH Individual characters FCH(PTOUT) PTIN PTOUT At this point PTIN is equal to SLSHLOC so the loop will terminate. The name has been flipped. PTIN is equal to SLSHLOC which is 8 so the loop will not be executed again.
24
The ability to give the location of a particular character
Flip Name Most languages have functions of commands to accomplish tasks that make the flipping of the name easier. The abilities you are looking for are: The ability to give the location of a particular character The ability to give the length of a field (the actual number of characters including embedded spaces) The ability to extract characters from the left of the field The ability to extract characters from the right of the field The ability to extract characters from the middle of the field (specify starting place and number of characters) Working with functions and commands. Check your language of choice for functions and commands that provide these abilities.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.