LogoLogo
Computing Skills
Computing Skills
  • Introduction
  • File Directory Structures
  • Text Editors
  • GitHub
  • Unix
  • Julia
    • Installation
    • REPL
    • Basic Syntax
    • Numbers and Math
    • Strings and Characters
    • Regular Expressions
    • Control Flow
    • Collections and Data Structures
    • File Input/Output
    • Packages
    • DataFrames
    • JuliaPlots
    • ScikitLearn.jl
    • JuliaStats
    • Exercises
  • Python
    • Installation
    • REPL
    • Basic Syntax
    • Numbers and Math
    • Strings and Characters
    • Regular Expressions
    • Control Flow
    • Collections and Data Structures
    • File Input/Output
    • Packages
    • Data Frames and Data Manipulation
  • R
    • Installation
    • REPL
    • Basic Syntax
    • Numbers and Math
    • Strings and Characters
    • Regular Expression
    • Control Flow
    • Collections and Data Structures
    • File Input/Output
    • Packages
    • DataFrames
    • Data Analysis and Manipulation
Powered by GitBook
On this page
  • Characters and Strings
  • Some functions that can be performed on strings
  • Resources
Export as PDF
  1. Julia

Strings and Characters

This page provides syntax for strings and characters in Julia as well as some of their associated functions. Each section includes an example to demonstrate the described syntax or function.

Characters and Strings

  • Char is a single character

  • String is a sequence of one or more characters (index values start at 1)

Some functions that can be performed on strings

Action
Function

get word length

length(word)

extract nth character from word

word[n]

extract substring nth-mth character from word

word[n:m]

search for letter in word

findfirst(isequal(letter), word)

search for subword in word

occursin(word, subword)

remove record separator from word (e.g., n)

chomp(word)

remove last character from word

chop(word)

Use typeof() function to determine type

Input:

# chars_and_strings.jl

letter = 'b'
word = "good-bye"
subword = "good"

word_length = length(word)
word_first_char = word[1]
word_subword = word[6:8]

println("Length of word: $word_length")
println("First character: $word_first_char")
println("Last three characters: $word_subword")

println("$letter is in $word: $(findfirst(isequal(letter), word))")
println("$subword is in $word: $(occursin(subword, word))")
println("chop off the last character: $(chop(word))")

Output:

Length of word: 8
First character: g
Last three characters: bye
b is in good-bye: 6
good is in good-bye: true
chop off the last character: good-by

Resources

PreviousNumbers and MathNextRegular Expressions

Last updated 6 months ago

Julia Documentation:

Julia Documentation:

Think Julia:

Manual - Strings
Base - Strings
Chapter 8 - Strings