A string is an array of characters to form words or numbers to make a statement.
Examples of strings:
Hello World
This is a string
e=mc^^2
Strings can also be numbers, but if you declare a number as a string, it will be treated as text and not as a number, so you will unable to process it via mathematical operators.
To declare a string within a one dimensional array, the number of characters should be declared within the square brackets.
An example of this would be;
Char str_word[size]
In this syntax the str_word is the name that is given to the variable, while the [size] is defined to the number of characters it will store.
To access the inside of an array, square brackets "[ ]" are needed to be used after the name of the array. This is commonly found within most of the languages in the "C" family when dealing with a string.
An example here will show how to access and print an array. If every character becomes an value in the array in this example of the string "Boo" it shows the forms of what the array would look like in the table on the side.
If the string is being accessed as an array the pseudocode would look like;
Let String = "Boo"
Print String[2]
This will result in printing the first lowercase "o" in the string of "Boo".
To extract data from a string, the characters will look at certain indexes and record the data within those indexes.
An example of this would be collecting the day, month and year where it is written as "DD/MM/YYYY"
Looking at this index and values table, it collects the characters from index 1 & 2 labelled as "DD" and records them as Dates, then displays them. It then moves to the indexes of 3 & 4 which is labelled as "MM" and records them as Months , then displays them. After that, it goes to the 5 - 8 indexes labelled as "YYYY" and records those as Years, then displays them.
Looking at this algorithm, it extracts data similar to the table in the previous slide, but it is only finding only the days and months. It states in both Days and Months will only have 2 characters.
So, if we were to put in a date such as the 22nd of August 2017 it would be written as 22/08/2017. By putting this into a similar table as the last slide we can see what is being recorded within the values sections.
Coding can be defined to remove the first instance of a word within a string.
In the string "I really really love chocolate", "really" has been detected to be put in twice, so it will remove the first "really" and change the string to "I really love chocolate". What it is set to do is to access the amount of letters of the string that is being repeated. So, in the given example, "really" is 6 characters long, which would mean it needs to access the first 6 characters. The characters seen from "really" are being searched for in each character and it goes through each index and increases it by one each search until all of the characters are looked at in that index. When the word is found, it removes that repeated word then brings the remaining words together and displays the final result, which would be “I really love chocolate”.
Concatenating strings is where the multiple strings combine to form into one string.
An example of this would be if the two strings of "Once upon a time" and the other string as "The end" turns into one string resulting with "Once upon a time The end".
A string can be entered into another string and then have them concatenate the strings together. A string can be combined with another string when a command is detected in the coding. So, if there is an intention to add something within the string, a dedicated character will be present to show that something will be placed there. In this Algorithm the symbol of the * is declared, which is used in one of the strings.
The string in the first example saying "I * love chocolate". If "*" was declared to add in the string "really", it would then split the two sections apart, add in the declared string which would then change the string to "I really love chocolate".
In the second example of “Ducks in boots” would be entered and it will result with the algorithm not finding the command and stating this when it says “the command * could not be found in your string”.