© Carlo Milanesi 2018
Carlo MilanesiBeginning Rusthttps://doi.org/10.1007/978-1-4842-3468-6_14

14. Using Changeable Strings

Carlo Milanesi1 
(1)
Bergamo, Italy
 
In this chapter, you will learn:
  • How static strings are implemented

  • How dynamic strings are implemented

  • How you can add characters to or remove characters from a dynamic string

  • How to convert a static string to a dynamic string, and conversely

  • How to concatenate strings

Static Strings

Are the strings that we have used so far changeable?

They may be mutable and so, in a sense, we can change them:

let mut a = "Hel";
print!("{}", a);
a = "lo";
print!("{}", a);

This will print "Hello". But in what sense did we change it? We changed abruptly all the content of the string, not just some characters. In ...

Get Beginning Rust: From Novice to Professional now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.