String handling operations in a programming language

EasyMedium
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
Question 30
Easy

The LOCATE_CHAR subroutine returns the position of the first occurrence of a character in a string (using 0-based indexing).

For example:

  • LOCATE_CHAR("Minecraft", "i") would return 1
  • LOCATE_CHAR("Minecraft", "c") would return 4

searchKey and game are variables used in the algorithm in Figure 1.

Complete the pseudo-code statement to find the position of the first occurrence of the contents of the variable searchKey in the variable game and store this position in the variable index.

You must use the LOCATE_CHAR subroutine in your answer.

Figure 1

game ← "Minecraft"
genre ← "Sandbox"
OUTPUT "Enter a character to search for:"
searchKey ← USERINPUT

index ←

[1]

String handling operations in a programming language Questions

  1. GCSE
  2. /Computer Science
  3. /String handling operations in a programming language