Topic: 2.3.5 Built-In Functions: Location
Topic: 2.3.5 Built-In Functions: Location
Topic: 2.3.5 Built-In Functions: Location
Many programming languages allow the searching for a short string of characters within a longer string.
This would be similar to searching this book for the word ‘computer’.
Common Key words for finding the location of one string within another are LOCATE, FIND and POSITION
Extraction
At times, a programmer will only want part of a string. Any part of a string can be obtained using the
RIGHT, LEFT and MID functions.
Page 1 of 7
Computer Science 9608 (Notes)
Chapter: 2.3 Programming
Concatenation is where two or more strings are joined together to make a single string.
Note that when two strings are added together the second string is added to the end of the first:
Length
Sometimes a programmer will need to know how many characters there are in a string.
Conversion
Strings are a sequence of ASCII characters, even if they contain only numbers such as “241”, and so they
cannot be used within an arithmetic calculation – they need to be ‘evaluated’ first.
Likewise a number such as 27.3 is not stored as ASCII characters and so cannot be used within any of the
string functions (such as Left, Right, Mid).
The function STR converts a number into a string and VAL converts a string into a number:
Page 2 of 7
Computer Science 9608 (Notes)
Chapter: 2.3 Programming
The following two functions are used to either find the ASCII code for a specific character or to find the
character from the ASCII code:
Below is a table showing the most common characters and their ASCII codes:
Page 3 of 7
Computer Science 9608 (Notes)
Chapter: 2.3 Programming
the codes less than 32 are ‘control’ codes that are not used in strings;
‘space’ (code 32) has the lowest code;
next comes most of the punctuation symbols;
then digits 0–9
then uppercase letters
then lowercase letters
all other characters (e.g. é, å, π, etc.) have codes higher than these.
Comparing strings
When comparing strings, the codes of each string are compared, character by character, to decide which
string is greater.
Because it is the ASCII codes that are compared the following applies:
in fact:
“Computing” < “computing”
“10” < “2”
“02” < “1”
“1 120” < “1,120”
“ computing” < “Computing”
Page 4 of 7
Computer Science 9608 (Notes)
Chapter: 2.3 Programming
The following table shows a list of inconsistently names music tracks and the order in which they would
be sorted:
In order to get them sorted into the required order, they must be renamed with consistent use of
uppercase letters, spaces and leading zeros.
Output data onto screen/file/printer, formatting the data for output as necessary.
Page 5 of 7
Computer Science 9608 (Notes)
Chapter: 2.3 Programming
Output to the screen could be via a dialogue/message box, a text box, a list box or simply direct on the
form.
Custom string formatting can be accomplished using specific characters recognized by the Format$
function, shown in the table below:
Page 6 of 7
Computer Science 9608 (Notes)
Chapter: 2.3 Programming
End Sub
Run the project and click the "Try It" button. When the input box appears, enter a name in mixed case (in
this example, Bruce was entered). The strings will be displayed as follows:
Page 7 of 7