Programming Fundamentals/Strings



This lesson introduces strings and string processing. A string is a data type used to represent integers instead of numbers in programming. This data type can contain spaces and numbers as well. You can edit string data types by something called string processing. This is when you edit the data in the string by adding, moving, or replacing characters using specific string functions.

Objectives and Skills
Objectives and skills for this lesson include:
 * Manipulate string data

Readings

 * 1) Pressbooks: Programming Fundamentals
 * 2)  String (computer science)

Multimedia

 * 1) YouTube: Programming Basics #28 String Concatenation
 * 2) YouTube: What Are Strings In Programming?
 * 3) YouTube: Computer programming tutorial: How to use strings
 * 4) Youtube: Strings - Intro to Computer Science
 * 5) YouTube: Programming/Scripting Concepts Explained (Variables, Arrays, Strings, & Length)

Examples

 * /Flowchart/
 * /Pseudocode/
 * /BASIC/
 * /C/
 * /C++/
 * C#
 * /Clojure/
 * /COBOL/
 * /Java/
 * /JavaScript/
 * /Lua/
 * /Perl/
 * /PHP/
 * /PowerShell/
 * /Python3/
 * /Ruby/
 * /Swift/
 * /VB.NET/

Activities
Complete the following activities using pseudocode, a flowcharting tool, or your selected programming language. Use separate functions for input, each type of processing, and output. Avoid global variables by passing parameters and returning results. Create test data to validate the accuracy of each program. Add comments at the top of the program and include references to any resources used.


 * 1) Create a program that asks the user for a single line of text containing a first name and last name, such as  . Use string functions/methods to parse the line and print out the name in the form last name, first initial, such as   Include a trailing period after the first initial. Handle invalid input errors, such as extra spaces or missing name parts.
 * 2) Create a program that asks the user for a line of text. Use string functions/methods to delete leading, trailing, and duplicate spaces, and then print the line of text backwards. For example:         Use separate subroutines/functions/methods to implement input, each type of processing, and output. Avoid global variables by passing parameters and returning results.
 * 3) Create a program that asks the user for a line of comma-separated-values. It could be a sequence of test scores, names, or any other values. Use string functions/methods to parse the line and print out each item on a separate line. Remove commas and any leading or trailing spaces from each item when printed.
 * 4) Create a program that asks the user for a line of text. Then ask the user for the number of characters to print in each line, the number of lines to be printed, and a scroll direction, right or left. Using the given line of text, duplicate the text as needed to fill the given number of characters per line. Then print the requested number of lines, shifting the entire line's content by one character, left or right, each time the line is printed. The first or last character will be shifted / appended to the other end of the string. For example, if shifting the line to the left:             Or if shifting the line to the right:

Lesson Summary

 * Most current programming languages include built-in or library functions to process strings. Common examples include case conversion, comparison, concatenation, find, join, length, reverse, split, substring, and trim.
 * Most current programming languages implement strings as a data type or class where strings are stored as a length controlled array. String length and storage are handled by the compiler or interpreter, reducing program errors.

Terms

 * buffer overflow
 * An anomaly where a program overruns a memory storage location and overwrites adjacent memory locations.


 * code injection
 * The exploitation of a computer bug that is caused by processing invalid data.


 * concatenation
 * The process in which you add two strings together in order to create a longer string


 * dynamic memory
 * Stack created memory associated with local scope. You now control the exact size and the lifetime of these memory locations.


 * join
 * Takes elements of an array/list, joins them together, and makes them into a string. Can also use a separator between each element.


 * split
 * Splits a string into a list.


 * static memory
 * Memory for your variables is allocated when the program starts. The size is fixed when the program is created. It applies to global variables, file scope variables, and variables qualified with static defined inside functions.


 * string
 * In most programming languages a string is a sequence of characters, either as a literal constant or as some kind of variable.


 * string formatting
 * uses a process of string interpolation (variable substitution) to evaluate a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.


 * string interpolation
 * Evaluating a string literal containing one or more placeholders, yielding a result in which the placeholders are replaced with their corresponding values.


 * title
 * A string method which is used to convert the first character in each word to uppercase and the remaining characters to lowercase and returns new string.

Assessments

 * Quizlet: Flash Cards
 * Quizlet 2