5 Working with text

 

This chapter covers

  • Representing text with the String type
  • Formatting text with lpad and rpad
  • Reading text from a keyboard or a file
  • Writing text to the screen or a file
  • Creating a simple interactive program

This chapter will focus on practical aspects of working with text in Julia, such has how do you show text on the screen, read or write it to a file. We will also look at simple interactive application where the user writes responses to questions.

However first we will focus on different ways of displaying text on the screen. We will revisit our our pizza sales and sine table examples. The tables we created before was not very readable. How about creating a neat display like this?

trig table CLI

Here sine and cosine values are neatly arranged in separate columns. Likewise would it not be better to neatly organize information about pizza sales into clearly separated columns, as seen below?

pizza sales CLI

5.1 Making a pretty pizza sales table

We will start by looking at the final result. The code we want to write, and then work our way backwards to explain how we got there. The code should not be entirely alien, but there are some new concepts which we need to explain.

5.1.2 Printing multiple elements

5.1.3 Printing multiple pizzas

5.1.4 Align with lpad and rpad

5.1.5 Adding lines

5.2 Printing a trigometric table

5.3 Reading and writing pizza sales to CSV files

5.3.1 Writing pizza sales to a file

5.3.2 Reading pizza sales from a file

5.4 Interacting with the user

5.5 Summary

sitemap