levo

Fundamentals of Programming

String-handling operations

  • 3 things to know
  • Paper 1
Start revising · £5/month

Overview

Recall questions on length, position, substring and concatenation, on where positions are counted from, and on converting between characters and their character codes.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Process

What does the length operation do? What is the length of 'Computing' and of the empty string?

Process

What does a string to float conversion do, and when do you need it rather than string to integer?

Key term

What does a date/time to string conversion do?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What does the length operation do? What is the length of 'Computing' and of the empty string?

    Model answer

    It returns the number of characters in a string. 'Computing' has length 9 and the empty string has length 0. Spaces and punctuation are characters and count towards the length, so 'A B' has length 3.

  2. 2

    What does the position operation do, and what does it return when the item is not there?

    Model answer

    It searches a string for a character or a substring and returns the index at which the first occurrence starts. If the item does not occur, it returns an agreed value that cannot be a valid index, typically -1 or 0 depending on the language. Only the first occurrence is reported, so finding later ones means searching again from beyond that point.

  3. 3

    Where does the position of a character get counted from, and why must you check this?

    Model answer

    Some languages number the characters of a string from 0 and others from 1, so in 'Computing' the letter 'm' is at position 2 counting from zero but at position 3 counting from one. Getting the base wrong produces answers that are consistently out by one, which is one of the commonest string-handling bugs.

  4. 4

    What does the substring operation do? Extract the first three characters of 'Computing'.

    Model answer

    It returns a section of a string, given a starting position and either a length or an end position. Taking three characters from the start of 'Computing' gives 'Com'. The original string is unchanged; the operation returns a new string.

  5. 5

    What does concatenation do, and what does 'Comp' joined to 'uting' give?

    Model answer

    It joins two strings end to end to produce a single longer string, so 'Comp' and 'uting' concatenate to 'Computing'. Nothing is inserted between them, so joining a first name to a surname needs a space concatenated in as well. In most languages the operator is +, though some use & or a join function.

  6. 6

    What does the character to character code operation do? What is the code for 'A'?

    Model answer

    It returns the numeric code that represents a given character in the coding scheme being used, so in ASCII the character 'A' gives 65. It is often written ord(c) or ASC(c).

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A driver is .
softwarehardwarestorage

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

Head means the first single element of a non-empty list.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Fundamentals of Programming, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.