String Manipulation

string-manipulation-0

String?


In computer science, a string is a piece of text or a collection of characters.
string-manipulation-1
A string can be stored in a variable, can be typed in by the end-user (input) or can be displayed on the screen (output).

In the above Python instruction: “Hello World” is a string. Notice the use of speech marks when using a string in code.

A string can be stored in a variable for instance.

String Concatenation


The act of joining two strings together is called string concatenation.
string-Concatenation

In Python string concatenation is done using the + sign:

String Manipulation Techniques


In computer programs it is often necessary to manipulate strings to:

  • Extract or truncate the first few characters of a string,
  • Extract or truncate some characters at the end of the string,
  • Find out the length (number of characters) of a string,
  • Convert a string from lowercase to UPPERCASE or vice-versa,
  • Check if a character has been used in a string,
  • Find out if a string contains a specific substring or word,
  • etc./li>

String Manipulation Challenges


Use our Block Programming tool to complete and test some String Manipulation challenges online.

string-manipulation-2

Share Button
Posted in Computer Science, Computing Concepts Tagged with:

Our Latest Book