Text is a fundamental type of data you'll work with in almost any programming task, from displaying messages to users, processing text files, or handling data from web services. Textual data in Julia is primarily handled using characters and strings. Guidance is provided for creating and manipulating these types.Characters: The Building BlocksA character, represented by the Char type in Julia, is a single letter, symbol, digit, or any other Unicode character. You define a character by enclosing it in single quotes.julia> c1 = 'A' 'A': ASCII/Unicode U+0041 (category Lu: Letter, uppercase) julia> c2 = 'π' 'π': Unicode U+03C0 (category Lm: Letter, modifier) julia> c3 = '7' '7': ASCII/Unicode U+0037 (category Nd: Number, decimal digit)Each Char in Julia represents a Unicode code point. This means Julia can handle a range of characters from different languages and symbol sets. You can even get the integer representation of a character:julia> Int('A') 65 julia> Int('α') 945Characters are the basic units that make up strings.Strings: Sequences of CharactersA string, type String in Julia, is an ordered sequence of characters. Strings are defined by enclosing text in double quotes " or triple double quotes """.julia> greeting = "Hello, Julia!" "Hello, Julia!" julia> fact = "Julia is a high-performance language." "Julia is a high-performance language."Julia strings are UTF-8 encoded by default, which is a common and efficient way to store Unicode characters. An important property of Julia strings is that they are immutable. This means that once a string is created, its content cannot be changed directly. Operations that appear to modify a string actually create a new string with the modified content.Combining Strings: ConcatenationYou often need to combine strings. This process is called concatenation. Julia provides a couple of straightforward ways to do this.The * operator, typically used for multiplication with numbers, is used for string concatenation:julia> first_name = "Ada" "Ada" julia> last_name = "Lovelace" "Lovelace" julia> full_name = first_name * " " * last_name "Ada Lovelace"Alternatively, you can use the string() function. This function is particularly useful when you want to combine multiple items, including non-string values, which it will attempt to convert to strings:julia> language = "Julia" "Julia" julia> version = 1.10 1.10 julia> message = string(language, " version ", version) "Julia version 1.10"Both methods result in a new string, leaving the original strings untouched, consistent with string immutability.digraph G { rankdir=TB; node [shape=record, style=filled, color="#adb5bd", fillcolor="#e9ecef"]; edge [color="#495057"]; s1 [label="s1 | \"Hello\""]; s2 [label="s2 | \" Julia\""]; s3 [label="s3 | \"Hello Julia\"", fillcolor="#96f2d7"]; op [label="*", shape=circle, style=filled, fillcolor="#fab005", fontcolor="white"]; s1 -> op [dir=none]; s2 -> op [dir=none]; op -> s3; }String concatenation with * creates a new string from the operands. s1 and s2 remain unchanged.Embedding Values in Strings: InterpolationString interpolation is a convenient way to insert the values of variables or expressions directly into a string. In Julia, you use the $ symbol for this.To embed a variable's value, prefix the variable name with $:julia> name = "World" "World" julia> salutation = "Hello, $name!" "Hello, World!"If you need to embed the result of an expression, enclose the expression in parentheses after the $:5 julia> y = 10 10 julia> calculation = "The sum of $x and $y is $(x + y)." "The sum of 5 and 10 is 15."Interpolation often leads to more readable code than repeated concatenation, especially for complex strings.Accessing String Content and PropertiesYou'll frequently need to know how long a string is, or access specific characters or parts of it.Length: The length() function returns the number of characters in a string.julia> s = "Julia" "Julia" julia> length(s) 5 julia> unicode_str = "你好世界" # "Hello World" in Chinese "你好世界" julia> length(unicode_str) 4 Notice how length() correctly counts characters, even for Unicode characters that might take multiple bytes to store.Indexing: You can access individual characters in a string using their index (position). Julia uses 1-based indexing, meaning the first character is at index 1.julia> s = "Julia" "Julia" julia> s[1] # First character 'J': ASCII/Unicode U+004A (category Lu: Letter, uppercase) julia> s[3] # Third character 'l': ASCII/Unicode U+006C (category Ll: Letter, lowercase) julia> s[end] # Last character (using 'end' keyword) 'a': ASCII/Unicode U+0061 (category Ll: Letter, lowercase)Attempting to access an index outside the valid range (e.g., s[0] or s[6] for "Julia") will result in an error.Slicing (Substrings): You can extract a portion of a string, called a substring, using a range of indices. This also creates a new string.julia> s = "Programming" "Programming" julia> s[1:4] # Characters from index 1 to 4 "Prog" julia> s[8:end] # Characters from index 8 to the end "ming" julia> s[5:7] "ram"Common String FunctionsJulia provides a rich set of built-in functions for string manipulation. Here are some of the most frequently used ones:Checking for Substrings:occursin(substring, string): Returns true if substring is found within string, false otherwise.julia> message = "Hello, Julia programmers!" "Hello, Julia programmers!" julia> occursin("Julia", message) true julia> occursin("Python", message) falsestartswith(string, prefix): Checks if string begins with prefix.endswith(string, suffix): Checks if string ends with suffix.julia> filename = "script.jl" "script.jl" julia> startswith(filename, "script") true julia> endswith(filename, ".jl") trueReplacing Substrings:replace(string, pattern => replacement): Creates a new string with occurrences of pattern replaced by replacement.julia> s = "I like apples." "I like apples." julia> replace(s, "apples" => "bananas") "I like bananas." julia> s # Original string is unchanged "I like apples."Changing Case:uppercase(string): Converts string to uppercase.lowercase(string): Converts string to lowercase.titlecase(string): Converts the first character of each word to uppercase.julia> phrase = "julia programming" "julia programming" julia> uppercase(phrase) "JULIA PROGRAMMING" julia> titlecase(phrase) "Julia Programming"Removing Whitespace:strip(string): Removes leading and trailing whitespace.lstrip(string): Removes leading whitespace.rstrip(string): Removes trailing whitespace.julia> padded_text = " some data " " some data " julia> strip(padded_text) "some data"Splitting and Joining Strings:split(string, delimiter): Splits string into a collection (an Array) of substrings based on delimiter.julia> csv_line = "apple,banana,cherry" "apple,banana,cherry" julia> fruits = split(csv_line, ',') 3-element Vector{String}: "apple" "banana" "cherry"Arrays are versatile collections that we will cover in detail in Chapter 4.join(collection, delimiter): Joins elements of a collection (e.g., an array of strings) into a single string, with delimiter inserted between elements.julia> words = ["Coding", "in", "Julia"] 3-element Vector{String}: "Coding" "in" "Julia" julia> sentence = join(words, " ") "Coding in Julia"Multi-line StringsFor text that spans multiple lines, such as poems, long messages, or embedded code snippets, Julia allows you to use triple double quotes """...""".julia> multi_line_str = """ This is a string that spans multiple lines. Indentation is also preserved if intended. """ "This is a string\nthat spans multiple\nlines.\nIndentation is also preserved\n if intended.\n"Julia is smart about handling indentation with triple-quoted strings. If your opening """ is on a line by itself, and the string content starts on the next line, Julia can optionally strip leading whitespace common to all content lines based on the indentation of the least-indented non-blank line. This helps keep your code tidy. For precise control, you can ensure the content starts on the same line as the opening """ or manage indentation explicitly.Julia's Strength with UnicodeIt's worth reiterating that Julia handles Unicode characters and strings robustly. Whether you're working with English, Chinese, Greek, emojis, or mathematical symbols, characters and strings generally behave as you'd expect. Functions like length(), indexing, and iteration work correctly at the character level, not just the byte level.julia> mixed_string = "Hello Γειά 你好 👋" "Hello Γειά 你好 👋" julia> length(mixed_string) 18 julia> for char in mixed_string print(char, " ") end H e l l o Γ ε ι ά 你 好 👋This built-in capability makes Julia an excellent choice for applications involving international text or specialized symbols.Working with characters and strings is a daily activity in programming. Mastering these basics will allow you to process textual information, create informative output, and build more interactive and useful Julia programs. As you progress, you'll discover even more powerful tools and packages for advanced text processing in the Julia ecosystem.