Small Steps I — Creating with Text and Numbers
Joining strings
Join Good, one space, and morning, then print the result.
What you will learn
For String values, + performs concatenation rather than numeric addition. The joined result is also a String value.
Try it
Example · example.cpp
void small_main()
{
String first = "Small";
String text = first + " C++";
print(text);
print(text.length());
}
text.length() returns the length of text. The dot means you are using an operation belonging to text. Spaces count too.
length is counted in bytes, a unit of data size. Each character in this English example is one byte. A Korean character in UTF-8 uses several bytes, so byte length may differ from character count.
Expected output:
Small C++
9
Exercise
Join Good, one space, and morning, then print the result.
Exercise starter · exercise_starter.cpp
void small_main()
{
String first = "Small";
String text = first + " C++";
print(text);
print(text.length());
}
Hint
Change the parts of the example that you need.
show solution
void small_main()
{
String first = "Good";
String text = first + " morning";
print(text);
}