Sophie

Sophie

distrib > Fedora > 20 > x86_64 > by-pkgid > d9f573299e87e886807be879704f0b6e > files > 142

julia-doc-0.3.4-1.fc20.noarch.rpm




<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  
  <title>Strings &mdash; Julia Language 0.3.4 documentation</title>
  

  
  

  
  <link href='https://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700|Inconsolata:400,700' rel='stylesheet' type='text/css'>

  
  
    

  

  
  
    <link rel="stylesheet" href="../_static/julia.css" type="text/css" />
  

  
    <link rel="stylesheet" href="../_static/julia.css" type="text/css" />
  
    <link rel="top" title="Julia Language 0.3.4 documentation" href="../index.html"/>
        <link rel="next" title="Functions" href="functions.html"/>
        <link rel="prev" title="Complex and Rational Numbers" href="complex-and-rational-numbers.html"/> 

  
  <script src="https://cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>

</head>

<body class="wy-body-for-nav" role="document">

  <div class="wy-grid-for-nav">

    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-nav-search">
        <a href="http://julialang.org/"><img src="../_static/julia-logo.svg" class="logo"></a>
        <!--
        <a href="../index.html" class="fa fa-home"> Julia Language</a>
        -->
        <div role="search">
  <form id ="rtd-search-form" class="wy-form" action="../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>
      </div>

      <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
        
        
            <ul class="current">
<li class="toctree-l1"><a class="reference internal" href="introduction.html">Introduction</a></li>
<li class="toctree-l1"><a class="reference internal" href="getting-started.html">Getting Started</a><ul>
<li class="toctree-l2"><a class="reference internal" href="getting-started.html#resources">Resources</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="variables.html">Variables</a><ul>
<li class="toctree-l2"><a class="reference internal" href="variables.html#allowed-variable-names">Allowed Variable Names</a></li>
<li class="toctree-l2"><a class="reference internal" href="variables.html#stylistic-conventions">Stylistic Conventions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="integers-and-floating-point-numbers.html">Integers and Floating-Point Numbers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#integers">Integers</a></li>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#floating-point-numbers">Floating-Point Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#arbitrary-precision-arithmetic">Arbitrary Precision Arithmetic</a></li>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#numeric-literal-coefficients">Numeric Literal Coefficients</a></li>
<li class="toctree-l2"><a class="reference internal" href="integers-and-floating-point-numbers.html#literal-zero-and-one">Literal zero and one</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="mathematical-operations.html">Mathematical Operations and Elementary Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#arithmetic-operators">Arithmetic Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#bitwise-operators">Bitwise Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#updating-operators">Updating operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#numeric-comparisons">Numeric Comparisons</a></li>
<li class="toctree-l2"><a class="reference internal" href="mathematical-operations.html#elementary-functions">Elementary Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="complex-and-rational-numbers.html">Complex and Rational Numbers</a><ul>
<li class="toctree-l2"><a class="reference internal" href="complex-and-rational-numbers.html#complex-numbers">Complex Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="complex-and-rational-numbers.html#rational-numbers">Rational Numbers</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="current reference internal" href="">Strings</a><ul>
<li class="toctree-l2"><a class="reference internal" href="#characters">Characters</a></li>
<li class="toctree-l2"><a class="reference internal" href="#string-basics">String Basics</a></li>
<li class="toctree-l2"><a class="reference internal" href="#unicode-and-utf-8">Unicode and UTF-8</a></li>
<li class="toctree-l2"><a class="reference internal" href="#interpolation">Interpolation</a></li>
<li class="toctree-l2"><a class="reference internal" href="#common-operations">Common Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="#non-standard-string-literals">Non-Standard String Literals</a></li>
<li class="toctree-l2"><a class="reference internal" href="#regular-expressions">Regular Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="#id3">Byte Array Literals</a></li>
<li class="toctree-l2"><a class="reference internal" href="#version-number-literals">Version Number Literals</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="functions.html">Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="functions.html#argument-passing-behavior">Argument Passing Behavior</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#the-return-keyword">The <tt class="docutils literal"><span class="pre">return</span></tt> Keyword</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#id1">Operators Are Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#operators-with-special-names">Operators With Special Names</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#anonymous-functions">Anonymous Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#multiple-return-values">Multiple Return Values</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#varargs-functions">Varargs Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#optional-arguments">Optional Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#keyword-arguments">Keyword Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#evaluation-scope-of-default-values">Evaluation Scope of Default Values</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#block-syntax-for-function-arguments">Block Syntax for Function Arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="functions.html#further-reading">Further Reading</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="control-flow.html">Control Flow</a><ul>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#compound-expressions">Compound Expressions</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#conditional-evaluation">Conditional Evaluation</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#short-circuit-evaluation">Short-Circuit Evaluation</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#repeated-evaluation-loops">Repeated Evaluation: Loops</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#exception-handling">Exception Handling</a></li>
<li class="toctree-l2"><a class="reference internal" href="control-flow.html#tasks-aka-coroutines">Tasks (aka Coroutines)</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="variables-and-scoping.html">Scope of Variables</a><ul>
<li class="toctree-l2"><a class="reference internal" href="variables-and-scoping.html#for-loops-and-comprehensions">For Loops and Comprehensions</a></li>
<li class="toctree-l2"><a class="reference internal" href="variables-and-scoping.html#constants">Constants</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="types.html">Types</a><ul>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-declarations">Type Declarations</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#abstract-types">Abstract Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#bits-types">Bits Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#composite-types">Composite Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#immutable-composite-types">Immutable Composite Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#declared-types">Declared Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#tuple-types">Tuple Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-unions">Type Unions</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#man-parametric-types">Parametric Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#type-aliases">Type Aliases</a></li>
<li class="toctree-l2"><a class="reference internal" href="types.html#operations-on-types">Operations on Types</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="methods.html">Methods</a><ul>
<li class="toctree-l2"><a class="reference internal" href="methods.html#defining-methods">Defining Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#method-ambiguities">Method Ambiguities</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#parametric-methods">Parametric Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="methods.html#note-on-optional-and-keyword-arguments">Note on Optional and keyword Arguments</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="constructors.html">Constructors</a><ul>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#outer-constructor-methods">Outer Constructor Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#inner-constructor-methods">Inner Constructor Methods</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#incomplete-initialization">Incomplete Initialization</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#parametric-constructors">Parametric Constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="constructors.html#case-study-rational">Case Study: Rational</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="conversion-and-promotion.html">Conversion and Promotion</a><ul>
<li class="toctree-l2"><a class="reference internal" href="conversion-and-promotion.html#conversion">Conversion</a></li>
<li class="toctree-l2"><a class="reference internal" href="conversion-and-promotion.html#promotion">Promotion</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="modules.html">Modules</a><ul>
<li class="toctree-l2"><a class="reference internal" href="modules.html#summary-of-module-usage">Summary of module usage</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="metaprogramming.html">Metaprogramming</a><ul>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#expressions-and-eval">Expressions and Eval</a></li>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#macros">Macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="metaprogramming.html#reflection">Reflection</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="arrays.html">Multi-dimensional Arrays</a><ul>
<li class="toctree-l2"><a class="reference internal" href="arrays.html#arrays">Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="arrays.html#sparse-matrices">Sparse Matrices</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="linear-algebra.html">Linear algebra</a><ul>
<li class="toctree-l2"><a class="reference internal" href="linear-algebra.html#matrix-factorizations">Matrix factorizations</a></li>
<li class="toctree-l2"><a class="reference internal" href="linear-algebra.html#special-matrices">Special matrices</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="networking-and-streams.html">Networking and Streams</a><ul>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#basic-stream-i-o">Basic Stream I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#text-i-o">Text I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#working-with-files">Working with Files</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#a-simple-tcp-example">A simple TCP example</a></li>
<li class="toctree-l2"><a class="reference internal" href="networking-and-streams.html#resolving-ip-addresses">Resolving IP Addresses</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="parallel-computing.html">Parallel Computing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#data-movement">Data Movement</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#parallel-map-and-loops">Parallel Map and Loops</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#synchronization-with-remote-references">Synchronization With Remote References</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#scheduling">Scheduling</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#distributed-arrays">Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#constructing-distributed-arrays">Constructing Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#distributed-array-operations">Distributed Array Operations</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#shared-arrays-experimental">Shared Arrays (Experimental)</a></li>
<li class="toctree-l2"><a class="reference internal" href="parallel-computing.html#clustermanagers">ClusterManagers</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="running-external-programs.html">Running External Programs</a><ul>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#interpolation">Interpolation</a></li>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#quoting">Quoting</a></li>
<li class="toctree-l2"><a class="reference internal" href="running-external-programs.html#pipelines">Pipelines</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="calling-c-and-fortran-code.html">Calling C and Fortran Code</a><ul>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#mapping-c-types-to-julia">Mapping C Types to Julia</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#accessing-data-through-a-pointer">Accessing Data through a Pointer</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#passing-pointers-for-modifying-inputs">Passing Pointers for Modifying Inputs</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#garbage-collection-safety">Garbage Collection Safety</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#non-constant-function-specifications">Non-constant Function Specifications</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#indirect-calls">Indirect Calls</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#calling-convention">Calling Convention</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#accessing-global-variables">Accessing Global Variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#passing-julia-callback-functions-to-c">Passing Julia Callback Functions to C</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#c">C++</a></li>
<li class="toctree-l2"><a class="reference internal" href="calling-c-and-fortran-code.html#handling-platform-variations">Handling Platform Variations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="interacting-with-julia.html">Interacting With Julia</a><ul>
<li class="toctree-l2"><a class="reference internal" href="interacting-with-julia.html#the-different-prompt-modes">The different prompt modes</a></li>
<li class="toctree-l2"><a class="reference internal" href="interacting-with-julia.html#key-bindings">Key bindings</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="embedding.html">Embedding Julia</a><ul>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#high-level-embedding">High-Level Embedding</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#converting-types">Converting Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#calling-julia-functions">Calling Julia Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#memory-management">Memory Management</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#working-with-arrays">Working with Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="embedding.html#exceptions">Exceptions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="packages.html">Packages</a><ul>
<li class="toctree-l2"><a class="reference internal" href="packages.html#package-status">Package Status</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#adding-and-removing-packages">Adding and Removing Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#installing-unregistered-packages">Installing Unregistered Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#updating-packages">Updating Packages</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#checkout-pin-and-free">Checkout, Pin and Free</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="packages.html#package-development">Package Development</a><ul>
<li class="toctree-l2"><a class="reference internal" href="packages.html#initial-setup">Initial Setup</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#generating-a-new-package">Generating a New Package</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#making-your-package-available">Making Your Package Available</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#publishing-your-package">Publishing Your Package</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#tagging-package-versions">Tagging Package Versions</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#fixing-package-requirements">Fixing Package Requirements</a></li>
<li class="toctree-l2"><a class="reference internal" href="packages.html#man-package-requirements">Requirements Specification</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="performance-tips.html">Performance Tips</a><ul>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-global-variables">Avoid global variables</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#measure-performance-with-time-and-pay-attention-to-memory-allocation">Measure performance with <tt class="docutils literal"><span class="pre">&#64;time</span></tt> and pay attention to memory allocation</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#tools">Tools</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-containers-with-abstract-type-parameters">Avoid containers with abstract type parameters</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#type-declarations">Type declarations</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#break-functions-into-multiple-definitions">Break functions into multiple definitions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#write-type-stable-functions">Write &#8220;type-stable&#8221; functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-changing-the-type-of-a-variable">Avoid changing the type of a variable</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#separate-kernel-functions">Separate kernel functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#access-arrays-in-memory-order-along-columns">Access arrays in memory order, along columns</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#pre-allocating-outputs">Pre-allocating outputs</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#avoid-string-interpolation-for-i-o">Avoid string interpolation for I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#fix-deprecation-warnings">Fix deprecation warnings</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#tweaks">Tweaks</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance-tips.html#performance-annotations">Performance Annotations</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="style-guide.html">Style Guide</a><ul>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#write-functions-not-just-scripts">Write functions, not just scripts</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-writing-overly-specific-types">Avoid writing overly-specific types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#handle-excess-argument-diversity-in-the-caller">Handle excess argument diversity in the caller</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#append-to-names-of-functions-that-modify-their-arguments">Append <cite>!</cite> to names of functions that modify their arguments</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-strange-type-unions">Avoid strange type Unions</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#try-to-avoid-nullable-fields">Try to avoid nullable fields</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-elaborate-container-types">Avoid elaborate container types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-underscores-in-names">Avoid underscores in names</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse-try-catch">Don&#8217;t overuse try-catch</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-parenthesize-conditions">Don&#8217;t parenthesize conditions</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse">Don&#8217;t overuse ...</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-use-unnecessary-static-parameters">Don&#8217;t use unnecessary static parameters</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#avoid-confusion-about-whether-something-is-an-instance-or-a-type">Avoid confusion about whether something is an instance or a type</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overuse-macros">Don&#8217;t overuse macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-expose-unsafe-operations-at-the-interface-level">Don&#8217;t expose unsafe operations at the interface level</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#don-t-overload-methods-of-base-container-types">Don&#8217;t overload methods of base container types</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#be-careful-with-type-equality">Be careful with type equality</a></li>
<li class="toctree-l2"><a class="reference internal" href="style-guide.html#do-not-write-x-f-x">Do not write <tt class="docutils literal"><span class="pre">x-&gt;f(x)</span></tt></a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="faq.html">Frequently Asked Questions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="faq.html#sessions-and-the-repl">Sessions and the REPL</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#functions">Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#types-type-declarations-and-constructors">Types, type declarations, and constructors</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#nothingness-and-missing-values">Nothingness and missing values</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#julia-releases">Julia Releases</a></li>
<li class="toctree-l2"><a class="reference internal" href="faq.html#developing-julia">Developing Julia</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="noteworthy-differences.html">Noteworthy Differences from other Languages</a><ul>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-matlab">Noteworthy differences from MATLAB</a></li>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-r">Noteworthy differences from R</a></li>
<li class="toctree-l2"><a class="reference internal" href="noteworthy-differences.html#noteworthy-differences-from-python">Noteworthy differences from Python</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/base.html">The Standard Library</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#introduction">Introduction</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#getting-around">Getting Around</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#all-objects">All Objects</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#types">Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#generic-functions">Generic Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#syntax">Syntax</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#iteration">Iteration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#general-collections">General Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#iterable-collections">Iterable Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#indexable-collections">Indexable Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#associative-collections">Associative Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#set-like-collections">Set-Like Collections</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#dequeues">Dequeues</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#strings">Strings</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#i-o">I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#network-i-o">Network I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#text-i-o">Text I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#multimedia-i-o">Multimedia I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#memory-mapped-i-o">Memory-mapped I/O</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#standard-numeric-types">Standard Numeric Types</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#mathematical-operators">Mathematical Operators</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#mathematical-functions">Mathematical Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#data-formats">Data Formats</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#numbers">Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#bigfloats">BigFloats</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#random-numbers">Random Numbers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#arrays">Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#combinatorics">Combinatorics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#statistics">Statistics</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#signal-processing">Signal Processing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#numerical-integration">Numerical Integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#parallel-computing">Parallel Computing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#distributed-arrays">Distributed Arrays</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#shared-arrays-experimental-unix-only-feature">Shared Arrays (Experimental, UNIX-only feature)</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#system">System</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#c-interface">C Interface</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#errors">Errors</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#tasks">Tasks</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#events">Events</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#reflection">Reflection</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/base.html#internals">Internals</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/sparse.html">Sparse Matrices</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/linalg.html">Linear Algebra</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/linalg.html#module-Base.LinAlg.BLAS">BLAS Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/constants.html">Constants</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/file.html">Filesystem</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/punctuation.html">Punctuation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/sort.html">Sorting and Related Functions</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#sorting-functions">Sorting Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#order-related-functions">Order-Related Functions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/sort.html#sorting-algorithms">Sorting Algorithms</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/pkg.html">Package Manager Functions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/collections.html">Collections and Data Structures</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/collections.html#priorityqueue">PriorityQueue</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/collections.html#heap-functions">Heap Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/graphics.html">Graphics</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/graphics.html#geometry">Geometry</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/test.html">Unit and Functional Testing</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#overview">Overview</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#handlers">Handlers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#macros">Macros</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/test.html#functions">Functions</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/test.html#testing-base-julia">Testing Base Julia</a></li>
<li class="toctree-l1"><a class="reference internal" href="../stdlib/profile.html">Profiling</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#basic-usage">Basic usage</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#accumulation-and-clearing">Accumulation and clearing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#options-for-controlling-the-display-of-profile-results">Options for controlling the display of profile results</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#configuration">Configuration</a></li>
<li class="toctree-l2"><a class="reference internal" href="../stdlib/profile.html#function-reference">Function reference</a></li>
</ul>
</li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../devdocs/julia.html">Documentation of Julia&#8217;s Internals</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/cartesian.html">Base.Cartesian</a></li>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/sysimg.html">System Image Building</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../devdocs/C.html">Developing/debugging Julia&#8217;s C code</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/backtraces.html">Reporting and analyzing crashes (segfaults)</a></li>
<li class="toctree-l2"><a class="reference internal" href="../devdocs/debuggingtips.html">gdb debugging tips</a></li>
</ul>
</li>
</ul>

        
      </div>
      &nbsp;
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" role="navigation" aria-label="top navigation">
        <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
        <a href="../index.html">Julia Language</a>
      </nav>


      
      <div class="wy-nav-content">
        <div class="rst-content">
          <div role="navigation" aria-label="breadcrumbs navigation">
  <ul class="wy-breadcrumbs">
    <li><a href="../index.html">Docs</a> &raquo;</li>
      
    <li>Strings</li>
      <li class="wy-breadcrumbs-aside">
        
          <a href="../_sources/manual/strings.txt" rel="nofollow"> View page source</a>
        
      </li>
  </ul>
  <hr/>
</div>
          <div role="main" class="document">
            
  <div class="section" id="strings">
<span id="man-strings"></span><h1>Strings<a class="headerlink" href="#strings" title="Permalink to this headline">¶</a></h1>
<p>Strings are finite sequences of characters. Of course, the real trouble
comes when one asks what a character is. The characters that English
speakers are familiar with are the letters <tt class="docutils literal"><span class="pre">A</span></tt>, <tt class="docutils literal"><span class="pre">B</span></tt>, <tt class="docutils literal"><span class="pre">C</span></tt>, etc.,
together with numerals and common punctuation symbols. These characters
are standardized together with a mapping to integer values between 0 and
127 by the <a class="reference external" href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> standard. There
are, of course, many other characters used in non-English languages,
including variants of the ASCII characters with accents and other
modifications, related scripts such as Cyrillic and Greek, and scripts
completely unrelated to ASCII and English, including Arabic, Chinese,
Hebrew, Hindi, Japanese, and Korean. The
<a class="reference external" href="http://en.wikipedia.org/wiki/Unicode">Unicode</a> standard tackles the
complexities of what exactly a character is, and is generally accepted
as the definitive standard addressing this problem. Depending on your
needs, you can either ignore these complexities entirely and just
pretend that only ASCII characters exist, or you can write code that can
handle any of the characters or encodings that one may encounter when
handling non-ASCII text. Julia makes dealing with plain ASCII text
simple and efficient, and handling Unicode is as simple and efficient as
possible. In particular, you can write C-style string code to process
ASCII strings, and they will work as expected, both in terms of
performance and semantics. If such code encounters non-ASCII text, it
will gracefully fail with a clear error message, rather than silently
introducing corrupt results. When this happens, modifying the code to
handle non-ASCII data is straightforward.</p>
<p>There are a few noteworthy high-level features about Julia&#8217;s strings:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">String</span></tt> is an abstraction, not a concrete type — many different
representations can implement the <tt class="docutils literal"><span class="pre">String</span></tt> interface, but they can
easily be used together and interact transparently. Any string type
can be used in any function expecting a <tt class="docutils literal"><span class="pre">String</span></tt>.</li>
<li>Like C and Java, but unlike most dynamic languages, Julia has a
first-class type representing a single character, called <tt class="docutils literal"><span class="pre">Char</span></tt>.
This is just a special kind of 32-bit integer whose numeric value
represents a Unicode code point.</li>
<li>As in Java, strings are immutable: the value of a <tt class="docutils literal"><span class="pre">String</span></tt> object
cannot be changed. To construct a different string value, you
construct a new string from parts of other strings.</li>
<li>Conceptually, a string is a <em>partial function</em> from indices to
characters — for some index values, no character value is returned,
and instead an exception is thrown. This allows for efficient
indexing into strings by the byte index of an encoded representation
rather than by a character index, which cannot be implemented both
efficiently and simply for variable-width encodings of Unicode
strings.</li>
<li>Julia supports the full range of
<a class="reference external" href="http://en.wikipedia.org/wiki/Unicode">Unicode</a> characters: literal
strings are always <a class="reference external" href="http://en.wikipedia.org/wiki/ASCII">ASCII</a> or
<a class="reference external" href="http://en.wikipedia.org/wiki/UTF-8">UTF-8</a> but other encodings for
strings from external sources can be supported.</li>
</ul>
<div class="section" id="characters">
<span id="man-characters"></span><h2>Characters<a class="headerlink" href="#characters" title="Permalink to this headline">¶</a></h2>
<p>A <tt class="docutils literal"><span class="pre">Char</span></tt> value represents a single character: it is just a 32-bit
integer with a special literal representation and appropriate arithmetic
behaviors, whose numeric value is interpreted as a <a class="reference external" href="http://en.wikipedia.org/wiki/Code_point">Unicode code
point</a>. Here is how <tt class="docutils literal"><span class="pre">Char</span></tt>
values are input and shown:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;x&#39;</span>
<span class="sc">&#39;x&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="n">Char</span>
</pre></div>
</div>
<p>You can convert a <tt class="docutils literal"><span class="pre">Char</span></tt> to its integer value, i.e. code point,
easily:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">int</span><span class="p">(</span><span class="sc">&#39;x&#39;</span><span class="p">)</span>
<span class="mi">120</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="kt">Int64</span>
</pre></div>
</div>
<p>On 32-bit architectures, <tt class="docutils literal"><span class="pre">typeof(ans)</span></tt> will be <tt class="docutils literal"><span class="pre">Int32</span></tt>. You can
convert an integer value back to a <tt class="docutils literal"><span class="pre">Char</span></tt> just as easily:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">char</span><span class="p">(</span><span class="mi">120</span><span class="p">)</span>
<span class="sc">&#39;x&#39;</span>
</pre></div>
</div>
<p>Not all integer values are valid Unicode code points, but for
performance, the <a class="reference internal" href="../stdlib/base.html#Base.char" title="Base.char"><tt class="xref jl jl-func docutils literal"><span class="pre">char()</span></tt></a> conversion does not check that every character
value is valid. If you want to check that each converted value is a
valid code point, use the <a class="reference internal" href="../stdlib/base.html#Base.is_valid_char" title="Base.is_valid_char"><tt class="xref jl jl-func docutils literal"><span class="pre">is_valid_char()</span></tt></a> function:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">char</span><span class="p">(</span><span class="mh">0x110000</span><span class="p">)</span>
<span class="sc">&#39;\U110000&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">is_valid_char</span><span class="p">(</span><span class="mh">0x110000</span><span class="p">)</span>
<span class="n">false</span>
</pre></div>
</div>
<p>As of this writing, the valid Unicode code points are <tt class="docutils literal"><span class="pre">U+00</span></tt> through
<tt class="docutils literal"><span class="pre">U+d7ff</span></tt> and <tt class="docutils literal"><span class="pre">U+e000</span></tt> through <tt class="docutils literal"><span class="pre">U+10ffff</span></tt>. These have not all been
assigned intelligible meanings yet, nor are they necessarily
interpretable by applications, but all of these values are considered to
be valid Unicode characters.</p>
<p>You can input any Unicode character in single quotes using <tt class="docutils literal"><span class="pre">\u</span></tt>
followed by up to four hexadecimal digits or <tt class="docutils literal"><span class="pre">\U</span></tt> followed by up to
eight hexadecimal digits (the longest valid value only requires six):</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;\u0&#39;</span>
<span class="sc">&#39;\0&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;\u78&#39;</span>
<span class="sc">&#39;x&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;\u2200&#39;</span>
<span class="sc">&#39;∀&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;\U10ffff&#39;</span>
<span class="sc">&#39;\U10ffff&#39;</span>
</pre></div>
</div>
<p>Julia uses your system&#8217;s locale and language settings to determine which
characters can be printed as-is and which must be output using the
generic, escaped <tt class="docutils literal"><span class="pre">\u</span></tt> or <tt class="docutils literal"><span class="pre">\U</span></tt> input forms. In addition to these
Unicode escape forms, all of <a class="reference external" href="http://en.wikipedia.org/wiki/C_syntax#Backslash_escapes">C&#8217;s traditional escaped input
forms</a> can
also be used:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">int</span><span class="p">(</span><span class="sc">&#39;\0&#39;</span><span class="p">)</span>
<span class="mi">0</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">int</span><span class="p">(</span><span class="sc">&#39;\t&#39;</span><span class="p">)</span>
<span class="mi">9</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">int</span><span class="p">(</span><span class="sc">&#39;\n&#39;</span><span class="p">)</span>
<span class="mi">10</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">int</span><span class="p">(</span><span class="sc">&#39;\e&#39;</span><span class="p">)</span>
<span class="mi">27</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">int</span><span class="p">(</span><span class="sc">&#39;\x7f&#39;</span><span class="p">)</span>
<span class="mi">127</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">int</span><span class="p">(</span><span class="sc">&#39;\177&#39;</span><span class="p">)</span>
<span class="mi">127</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">int</span><span class="p">(</span><span class="sc">&#39;\xff&#39;</span><span class="p">)</span>
<span class="mi">255</span>
</pre></div>
</div>
<p>You can do comparisons and a limited amount of arithmetic with
<tt class="docutils literal"><span class="pre">Char</span></tt> values:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;A&#39;</span> <span class="o">&lt;</span> <span class="sc">&#39;a&#39;</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;A&#39;</span> <span class="o">&lt;=</span> <span class="sc">&#39;a&#39;</span> <span class="o">&lt;=</span> <span class="sc">&#39;Z&#39;</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;A&#39;</span> <span class="o">&lt;=</span> <span class="sc">&#39;X&#39;</span> <span class="o">&lt;=</span> <span class="sc">&#39;Z&#39;</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;x&#39;</span> <span class="o">-</span> <span class="sc">&#39;a&#39;</span>
<span class="mi">23</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="sc">&#39;A&#39;</span> <span class="o">+</span> <span class="mi">1</span>
<span class="sc">&#39;B&#39;</span>
</pre></div>
</div>
</div>
<div class="section" id="string-basics">
<h2>String Basics<a class="headerlink" href="#string-basics" title="Permalink to this headline">¶</a></h2>
<p>String literals are delimited by double quotes or triple double quotes:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span> <span class="o">=</span> <span class="s">&quot;Hello, world.</span><span class="se">\n</span><span class="s">&quot;</span>
<span class="s">&quot;Hello, world.</span><span class="se">\n</span><span class="s">&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;&quot;&quot;Contains &quot;</span><span class="k">quote</span><span class="s">&quot; characters&quot;&quot;&quot;</span>
<span class="s">&quot;Contains </span><span class="se">\&quot;</span><span class="s">quote</span><span class="se">\&quot;</span><span class="s"> characters&quot;</span>
</pre></div>
</div>
<p>If you want to extract a character from a string, you index into it:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="sc">&#39;H&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="mi">6</span><span class="p">]</span>
<span class="sc">&#39;,&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="k">end</span><span class="p">]</span>
<span class="sc">&#39;\n&#39;</span>
</pre></div>
</div>
<p>All indexing in Julia is 1-based: the first element of any
integer-indexed object is found at index 1, and the last
element is found at index <tt class="docutils literal"><span class="pre">n</span></tt>, when the string has
a length of <tt class="docutils literal"><span class="pre">n</span></tt>.</p>
<p>In any indexing expression, the keyword <tt class="docutils literal"><span class="pre">end</span></tt> can be used as a
shorthand for the last index (computed by <tt class="docutils literal"><span class="pre">endof(str)</span></tt>).
You can perform arithmetic and other operations with <tt class="docutils literal"><span class="pre">end</span></tt>, just like
a normal value:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="k">end</span><span class="o">-</span><span class="mi">1</span><span class="p">]</span>
<span class="sc">&#39;.&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="k">end</span><span class="o">/</span><span class="mi">2</span><span class="p">]</span>
<span class="sc">&#39; &#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="k">end</span><span class="o">/</span><span class="mi">3</span><span class="p">]</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">InexactError</span><span class="p">()</span>
 <span class="k">in</span> <span class="n">getindex</span> <span class="n">at</span> <span class="n">string</span><span class="o">.</span><span class="n">jl</span><span class="p">:</span><span class="mi">59</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="k">end</span><span class="o">/</span><span class="mi">4</span><span class="p">]</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">InexactError</span><span class="p">()</span>
 <span class="k">in</span> <span class="n">getindex</span> <span class="n">at</span> <span class="n">string</span><span class="o">.</span><span class="n">jl</span><span class="p">:</span><span class="mi">59</span>
</pre></div>
</div>
<p>Using an index less than 1 or greater than <tt class="docutils literal"><span class="pre">end</span></tt> raises an error:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">BoundsError</span><span class="p">()</span>
 <span class="k">in</span> <span class="n">getindex</span> <span class="n">at</span> <span class="o">/</span><span class="n">Users</span><span class="o">/</span><span class="n">sabae</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">julia</span><span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">julia</span><span class="o">/</span><span class="n">sys</span><span class="o">.</span><span class="n">dylib</span> <span class="p">(</span><span class="n">repeats</span> <span class="mi">2</span> <span class="n">times</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="k">end</span><span class="o">+</span><span class="mi">1</span><span class="p">]</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">BoundsError</span><span class="p">()</span>
 <span class="k">in</span> <span class="n">getindex</span> <span class="n">at</span> <span class="o">/</span><span class="n">Users</span><span class="o">/</span><span class="n">sabae</span><span class="o">/</span><span class="n">src</span><span class="o">/</span><span class="n">julia</span><span class="o">/</span><span class="n">usr</span><span class="o">/</span><span class="n">lib</span><span class="o">/</span><span class="n">julia</span><span class="o">/</span><span class="n">sys</span><span class="o">.</span><span class="n">dylib</span> <span class="p">(</span><span class="n">repeats</span> <span class="mi">2</span> <span class="n">times</span><span class="p">)</span>
</pre></div>
</div>
<p>You can also extract a substring using range indexing:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="mi">4</span><span class="p">:</span><span class="mi">9</span><span class="p">]</span>
<span class="s">&quot;lo, wo&quot;</span>
</pre></div>
</div>
<p>Notice that the expressions <tt class="docutils literal"><span class="pre">str[k]</span></tt> and <tt class="docutils literal"><span class="pre">str[k:k]</span></tt> do not give the same result:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="mi">6</span><span class="p">]</span>
<span class="sc">&#39;,&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">str</span><span class="p">[</span><span class="mi">6</span><span class="p">:</span><span class="mi">6</span><span class="p">]</span>
<span class="s">&quot;,&quot;</span>
</pre></div>
</div>
<p>The former is a single character value of type <tt class="docutils literal"><span class="pre">Char</span></tt>, while the
latter is a string value that happens to contain only a single
character. In Julia these are very different things.</p>
</div>
<div class="section" id="unicode-and-utf-8">
<h2>Unicode and UTF-8<a class="headerlink" href="#unicode-and-utf-8" title="Permalink to this headline">¶</a></h2>
<p>Julia fully supports Unicode characters and strings. As <a class="reference external" href="#characters">discussed
above</a>, in character literals, Unicode code points can be
represented using Unicode <tt class="docutils literal"><span class="pre">\u</span></tt> and <tt class="docutils literal"><span class="pre">\U</span></tt> escape sequences, as well as
all the standard C escape sequences. These can likewise be used to write
string literals:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">s</span> <span class="o">=</span> <span class="s">&quot;</span><span class="se">\u2200</span><span class="s"> x </span><span class="se">\u2203</span><span class="s"> y&quot;</span>
<span class="s">&quot;∀ x ∃ y&quot;</span>
</pre></div>
</div>
<p>Whether these Unicode characters are displayed as escapes or shown as
special characters depends on your terminal&#8217;s locale settings and its
support for Unicode. Non-ASCII string literals are encoded using the
UTF-8 encoding. UTF-8 is a variable-width encoding, meaning that not all
characters are encoded in the same number of bytes. In UTF-8, ASCII
characters — i.e. those with code points less than 0x80 (128) —&nbsp;are
encoded as they are in ASCII, using a single byte, while code points
0x80 and above are encoded using multiple bytes —&nbsp;up to four per
character. This means that not every byte index into a UTF-8 string is
necessarily a valid index for a character. If you index into a string at
such an invalid byte index, an error is thrown:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">s</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span>
<span class="sc">&#39;∀&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">s</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">invalid</span> <span class="n">UTF</span><span class="o">-</span><span class="mi">8</span> <span class="n">character</span> <span class="n">index</span>
 <span class="k">in</span> <span class="n">next</span> <span class="n">at</span> <span class="o">./</span><span class="n">utf8</span><span class="o">.</span><span class="n">jl</span><span class="p">:</span><span class="mi">68</span>
 <span class="k">in</span> <span class="n">getindex</span> <span class="n">at</span> <span class="n">string</span><span class="o">.</span><span class="n">jl</span><span class="p">:</span><span class="mi">57</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">s</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">invalid</span> <span class="n">UTF</span><span class="o">-</span><span class="mi">8</span> <span class="n">character</span> <span class="n">index</span>
 <span class="k">in</span> <span class="n">next</span> <span class="n">at</span> <span class="o">./</span><span class="n">utf8</span><span class="o">.</span><span class="n">jl</span><span class="p">:</span><span class="mi">68</span>
 <span class="k">in</span> <span class="n">getindex</span> <span class="n">at</span> <span class="n">string</span><span class="o">.</span><span class="n">jl</span><span class="p">:</span><span class="mi">57</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">s</span><span class="p">[</span><span class="mi">4</span><span class="p">]</span>
<span class="sc">&#39; &#39;</span>
</pre></div>
</div>
<p>In this case, the character <tt class="docutils literal"><span class="pre">∀</span></tt> is a three-byte character, so the
indices 2 and 3 are invalid and the next character&#8217;s index is 4.</p>
<p>Because of variable-length encodings, the number of characters in a
string (given by <tt class="docutils literal"><span class="pre">length(s)</span></tt>) is not always the same as the last index.
If you iterate through the indices 1 through <tt class="docutils literal"><span class="pre">endof(s)</span></tt> and index
into <tt class="docutils literal"><span class="pre">s</span></tt>, the sequence of characters returned when errors aren&#8217;t
thrown is the sequence of characters comprising the string <tt class="docutils literal"><span class="pre">s</span></tt>.
Thus we have the identity that <tt class="docutils literal"><span class="pre">length(s)</span> <span class="pre">&lt;=</span> <span class="pre">endof(s)</span></tt>, since each
character in a string must have its own index. The following is an
inefficient and verbose way to iterate through the characters of <tt class="docutils literal"><span class="pre">s</span></tt>:</p>
<div class="highlight-julia"><pre>julia&gt; for i = 1:endof(s)
         try
           println(s[i])
         catch
           # ignore the index error
         end
       end
∀

x

∃

y</pre>
</div>
<p>The blank lines actually have spaces on them. Fortunately, the above
awkward idiom is unnecessary for iterating through the characters in a
string, since you can just use the string as an iterable object, no
exception handling required:</p>
<div class="highlight-julia"><pre>julia&gt; for c in s
         println(c)
       end
∀

x

∃

y</pre>
</div>
<p>UTF-8 is not the only encoding that Julia supports, and adding support
for new encodings is quite easy.  In particular, Julia also provides
<tt class="docutils literal"><span class="pre">UTF16String</span></tt> and <tt class="docutils literal"><span class="pre">UTF32String</span></tt> types, constructed by the
<tt class="docutils literal"><span class="pre">utf16(s)</span></tt> and <tt class="docutils literal"><span class="pre">utf32(s)</span></tt> functions respectively, for UTF-16 and
UTF-32 encodings.  It also provides aliases <tt class="docutils literal"><span class="pre">WString</span></tt> and
<tt class="docutils literal"><span class="pre">wstring(s)</span></tt> for either UTF-16 or UTF-32 strings, depending on the
size of <tt class="docutils literal"><span class="pre">Cwchar_t</span></tt>. Additional discussion of other encodings and how to
implement support for them is beyond the scope of this document for
the time being. For further discussion of UTF-8 encoding issues, see
the section below on <a class="reference external" href="#Byte+Array+Literals">byte array literals</a>,
which goes into some greater detail.</p>
</div>
<div class="section" id="interpolation">
<span id="man-string-interpolation"></span><h2>Interpolation<a class="headerlink" href="#interpolation" title="Permalink to this headline">¶</a></h2>
<p>One of the most common and useful string operations is concatenation:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">greet</span> <span class="o">=</span> <span class="s">&quot;Hello&quot;</span>
<span class="s">&quot;Hello&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">whom</span> <span class="o">=</span> <span class="s">&quot;world&quot;</span>
<span class="s">&quot;world&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">string</span><span class="p">(</span><span class="n">greet</span><span class="p">,</span> <span class="s">&quot;, &quot;</span><span class="p">,</span> <span class="n">whom</span><span class="p">,</span> <span class="s">&quot;.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span>
<span class="s">&quot;Hello, world.</span><span class="se">\n</span><span class="s">&quot;</span>
</pre></div>
</div>
<p>Constructing strings like this can become a bit cumbersome, however. To
reduce the need for these verbose calls to <a class="reference internal" href="../stdlib/base.html#Base.string" title="Base.string"><tt class="xref jl jl-func docutils literal"><span class="pre">string()</span></tt></a>, Julia allows
interpolation into string literals using <tt class="docutils literal"><span class="pre">$</span></tt>, as in Perl:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;</span><span class="si">$</span><span class="s">greet, </span><span class="si">$</span><span class="s">whom.</span><span class="se">\n</span><span class="s">&quot;</span>
<span class="s">&quot;Hello, world.</span><span class="se">\n</span><span class="s">&quot;</span>
</pre></div>
</div>
<p>This is more readable and convenient and equivalent to the above string
concatenation — the system rewrites this apparent single string literal
into a concatenation of string literals with variables.</p>
<p>The shortest complete expression after the <tt class="docutils literal"><span class="pre">$</span></tt> is taken as the
expression whose value is to be interpolated into the string. Thus, you
can interpolate any expression into a string using parentheses:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;1 + 2 = </span><span class="si">$</span><span class="s">(1 + 2)&quot;</span>
<span class="s">&quot;1 + 2 = 3&quot;</span>
</pre></div>
</div>
<p>Both concatenation and string interpolation call the generic <tt class="docutils literal"><span class="pre">string</span></tt>
function to convert objects into <tt class="docutils literal"><span class="pre">String</span></tt> form. Most non-<tt class="docutils literal"><span class="pre">String</span></tt>
objects are converted to strings as they are shown in interactive
sessions:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">v</span> <span class="o">=</span> <span class="p">[</span><span class="mi">1</span><span class="p">,</span><span class="mi">2</span><span class="p">,</span><span class="mi">3</span><span class="p">]</span>
<span class="mi">3</span><span class="o">-</span><span class="n">element</span> <span class="n">Array</span><span class="p">{</span><span class="kt">Int64</span><span class="p">,</span><span class="mi">1</span><span class="p">}:</span>
 <span class="mi">1</span>
 <span class="mi">2</span>
 <span class="mi">3</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;v: </span><span class="si">$</span><span class="s">v&quot;</span>
<span class="s">&quot;v: [1,2,3]&quot;</span>
</pre></div>
</div>
<p>The <tt class="docutils literal"><span class="pre">string</span></tt> function is the identity for <tt class="docutils literal"><span class="pre">String</span></tt> and <tt class="docutils literal"><span class="pre">Char</span></tt>
values, so these are interpolated into strings as themselves, unquoted
and unescaped:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">c</span> <span class="o">=</span> <span class="sc">&#39;x&#39;</span>
<span class="sc">&#39;x&#39;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;hi, </span><span class="si">$</span><span class="s">c&quot;</span>
<span class="s">&quot;hi, x&quot;</span>
</pre></div>
</div>
<p>To include a literal <tt class="docutils literal"><span class="pre">$</span></tt> in a string literal, escape it with a
backslash:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">print</span><span class="p">(</span><span class="s">&quot;I have \</span><span class="si">$100</span><span class="s"> in my account.</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span>
<span class="n">I</span> <span class="n">have</span> <span class="o">$</span><span class="mi">100</span> <span class="k">in</span> <span class="n">my</span> <span class="n">account</span><span class="o">.</span>
</pre></div>
</div>
</div>
<div class="section" id="common-operations">
<h2>Common Operations<a class="headerlink" href="#common-operations" title="Permalink to this headline">¶</a></h2>
<p>You can lexicographically compare strings using the standard comparison
operators:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;abracadabra&quot;</span> <span class="o">&lt;</span> <span class="s">&quot;xylophone&quot;</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;abracadabra&quot;</span> <span class="o">==</span> <span class="s">&quot;xylophone&quot;</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;Hello, world.&quot;</span> <span class="o">!=</span> <span class="s">&quot;Goodbye, world.&quot;</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;1 + 2 = 3&quot;</span> <span class="o">==</span> <span class="s">&quot;1 + 2 = </span><span class="si">$</span><span class="s">(1 + 2)&quot;</span>
<span class="n">true</span>
</pre></div>
</div>
<p>You can search for the index of a particular character using the
<a class="reference internal" href="../stdlib/base.html#Base.search" title="Base.search"><tt class="xref jl jl-func docutils literal"><span class="pre">search()</span></tt></a> function:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">search</span><span class="p">(</span><span class="s">&quot;xylophone&quot;</span><span class="p">,</span> <span class="sc">&#39;x&#39;</span><span class="p">)</span>
<span class="mi">1</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">search</span><span class="p">(</span><span class="s">&quot;xylophone&quot;</span><span class="p">,</span> <span class="sc">&#39;p&#39;</span><span class="p">)</span>
<span class="mi">5</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">search</span><span class="p">(</span><span class="s">&quot;xylophone&quot;</span><span class="p">,</span> <span class="sc">&#39;z&#39;</span><span class="p">)</span>
<span class="mi">0</span>
</pre></div>
</div>
<p>You can start the search for a character at a given offset by providing
a third argument:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">search</span><span class="p">(</span><span class="s">&quot;xylophone&quot;</span><span class="p">,</span> <span class="sc">&#39;o&#39;</span><span class="p">)</span>
<span class="mi">4</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">search</span><span class="p">(</span><span class="s">&quot;xylophone&quot;</span><span class="p">,</span> <span class="sc">&#39;o&#39;</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="mi">7</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">search</span><span class="p">(</span><span class="s">&quot;xylophone&quot;</span><span class="p">,</span> <span class="sc">&#39;o&#39;</span><span class="p">,</span> <span class="mi">8</span><span class="p">)</span>
<span class="mi">0</span>
</pre></div>
</div>
<p>You can use the <a class="reference internal" href="../stdlib/base.html#Base.contains" title="Base.contains"><tt class="xref jl jl-func docutils literal"><span class="pre">contains()</span></tt></a> function to check if a substring is
contained in a string:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">contains</span><span class="p">(</span><span class="s">&quot;Hello, world.&quot;</span><span class="p">,</span> <span class="s">&quot;world&quot;</span><span class="p">)</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">contains</span><span class="p">(</span><span class="s">&quot;Xylophon&quot;</span><span class="p">,</span> <span class="s">&quot;o&quot;</span><span class="p">)</span>
<span class="n">true</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">contains</span><span class="p">(</span><span class="s">&quot;Xylophon&quot;</span><span class="p">,</span> <span class="s">&quot;a&quot;</span><span class="p">)</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">contains</span><span class="p">(</span><span class="s">&quot;Xylophon&quot;</span><span class="p">,</span> <span class="sc">&#39;o&#39;</span><span class="p">)</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="sb">`contains`</span> <span class="n">has</span> <span class="n">no</span> <span class="n">method</span> <span class="n">matching</span> <span class="n">contains</span><span class="p">(::</span><span class="n">ASCIIString</span><span class="p">,</span> <span class="p">::</span><span class="n">Char</span><span class="p">)</span>
</pre></div>
</div>
<p>The last error is because <tt class="docutils literal"><span class="pre">'o'</span></tt> is a character literal, and <a class="reference internal" href="../stdlib/base.html#Base.contains" title="Base.contains"><tt class="xref jl jl-func docutils literal"><span class="pre">contains()</span></tt></a>
is a generic function that looks for subsequences. To look for an element in a
sequence, you must use the <a class="reference internal" href="../stdlib/base.html#Base.in" title="Base.in"><tt class="xref jl jl-func docutils literal"><span class="pre">in()</span></tt></a> function instead.</p>
<p>Two other handy string functions are <a class="reference internal" href="../stdlib/linalg.html#Base.repeat" title="Base.repeat"><tt class="xref jl jl-func docutils literal"><span class="pre">repeat()</span></tt></a> and <a class="reference internal" href="../stdlib/base.html#Base.join" title="Base.join"><tt class="xref jl jl-func docutils literal"><span class="pre">join()</span></tt></a>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">repeat</span><span class="p">(</span><span class="s">&quot;.:Z:.&quot;</span><span class="p">,</span> <span class="mi">10</span><span class="p">)</span>
<span class="s">&quot;.:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:..:Z:.&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">join</span><span class="p">([</span><span class="s">&quot;apples&quot;</span><span class="p">,</span> <span class="s">&quot;bananas&quot;</span><span class="p">,</span> <span class="s">&quot;pineapples&quot;</span><span class="p">],</span> <span class="s">&quot;, &quot;</span><span class="p">,</span> <span class="s">&quot; and &quot;</span><span class="p">)</span>
<span class="s">&quot;apples, bananas and pineapples&quot;</span>
</pre></div>
</div>
<p>Some other useful functions include:</p>
<ul class="simple">
<li><tt class="docutils literal"><span class="pre">endof(str)</span></tt> gives the maximal (byte) index that can be used to
index into <tt class="docutils literal"><span class="pre">str</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">length(str)</span></tt> the number of characters in <tt class="docutils literal"><span class="pre">str</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">i</span> <span class="pre">=</span> <span class="pre">start(str)</span></tt> gives the first valid index at which a character
can be found in <tt class="docutils literal"><span class="pre">str</span></tt> (typically 1).</li>
<li><tt class="docutils literal"><span class="pre">c,</span> <span class="pre">j</span> <span class="pre">=</span> <span class="pre">next(str,i)</span></tt> returns next character at or after the index
<tt class="docutils literal"><span class="pre">i</span></tt> and the next valid character index following that. With
<tt class="docutils literal"><span class="pre">start</span></tt> and <tt class="docutils literal"><span class="pre">endof</span></tt>, can be used to iterate through the
characters in <tt class="docutils literal"><span class="pre">str</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">ind2chr(str,i)</span></tt> gives the number of characters in <tt class="docutils literal"><span class="pre">str</span></tt> up to
and including any at index <tt class="docutils literal"><span class="pre">i</span></tt>.</li>
<li><tt class="docutils literal"><span class="pre">chr2ind(str,j)</span></tt> gives the index at which the <tt class="docutils literal"><span class="pre">j</span></tt>th character
in <tt class="docutils literal"><span class="pre">str</span></tt> occurs.</li>
</ul>
</div>
<div class="section" id="non-standard-string-literals">
<span id="man-non-standard-string-literals"></span><h2>Non-Standard String Literals<a class="headerlink" href="#non-standard-string-literals" title="Permalink to this headline">¶</a></h2>
<p>There are situations when you want to construct a string or use string
semantics, but the behavior of the standard string construct is not
quite what is needed. For these kinds of situations, Julia provides
<a class="reference internal" href="metaprogramming.html#man-non-standard-string-literals2"><em>non-standard string literals</em></a>.
A non-standard string literal looks like
a regular double-quoted string literal, but is immediately prefixed by
an identifier, and doesn&#8217;t behave quite like a normal string literal. Regular
expressions, byte array literals and version number literals, as described
below, are some examples of non-standard string literals. Other examples are
given in the <a class="reference internal" href="metaprogramming.html#man-non-standard-string-literals2"><em>metaprogramming</em></a>
section.</p>
</div>
<div class="section" id="regular-expressions">
<h2>Regular Expressions<a class="headerlink" href="#regular-expressions" title="Permalink to this headline">¶</a></h2>
<p>Julia has Perl-compatible regular expressions (regexes), as provided by
the <a class="reference external" href="http://www.pcre.org/">PCRE</a> library. Regular expressions are
related to strings in two ways: the obvious connection is that regular
expressions are used to find regular patterns in strings; the other
connection is that regular expressions are themselves input as strings,
which are parsed into a state machine that can be used to efficiently
search for patterns in strings. In Julia, regular expressions are input
using non-standard string literals prefixed with various identifiers
beginning with <tt class="docutils literal"><span class="pre">r</span></tt>. The most basic regular expression literal without
any options turned on just uses <tt class="docutils literal"><span class="pre">r&quot;...&quot;</span></tt>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">r</span><span class="s">&quot;^\s*(?:#|</span><span class="si">$</span><span class="s">)&quot;</span>
<span class="n">r</span><span class="s">&quot;^\s*(?:#|</span><span class="si">$</span><span class="s">)&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="nb">typeof</span><span class="p">(</span><span class="n">ans</span><span class="p">)</span>
<span class="n">Regex</span> <span class="p">(</span><span class="n">constructor</span> <span class="n">with</span> <span class="mi">3</span> <span class="n">methods</span><span class="p">)</span>
</pre></div>
</div>
<p>To check if a regex matches a string, use the <a class="reference internal" href="../stdlib/base.html#Base.ismatch" title="Base.ismatch"><tt class="xref jl jl-func docutils literal"><span class="pre">ismatch()</span></tt></a> function:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">ismatch</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;^\s*(?:#|</span><span class="si">$</span><span class="s">)&quot;</span><span class="p">,</span> <span class="s">&quot;not a comment&quot;</span><span class="p">)</span>
<span class="n">false</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">ismatch</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;^\s*(?:#|</span><span class="si">$</span><span class="s">)&quot;</span><span class="p">,</span> <span class="s">&quot;# a comment&quot;</span><span class="p">)</span>
<span class="n">true</span>
</pre></div>
</div>
<p>As one can see here, <tt class="docutils literal"><span class="pre">ismatch</span></tt> simply returns true or false,
indicating whether the given regex matches the string or not. Commonly,
however, one wants to know not just whether a string matched, but also
<em>how</em> it matched. To capture this information about a match, use the
<a class="reference internal" href="../stdlib/base.html#Base.match" title="Base.match"><tt class="xref jl jl-func docutils literal"><span class="pre">match()</span></tt></a> function instead:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;^\s*(?:#|</span><span class="si">$</span><span class="s">)&quot;</span><span class="p">,</span> <span class="s">&quot;not a comment&quot;</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;^\s*(?:#|</span><span class="si">$</span><span class="s">)&quot;</span><span class="p">,</span> <span class="s">&quot;# a comment&quot;</span><span class="p">)</span>
<span class="n">RegexMatch</span><span class="p">(</span><span class="s">&quot;#&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>If the regular expression does not match the given string, <tt class="docutils literal"><span class="pre">match</span></tt>
returns <tt class="docutils literal"><span class="pre">nothing</span></tt> — a special value that does not print anything at
the interactive prompt. Other than not printing, it is a completely
normal value and you can test for it programmatically:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">m</span> <span class="o">=</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;^\s*(?:#|</span><span class="si">$</span><span class="s">)&quot;</span><span class="p">,</span> <span class="n">line</span><span class="p">)</span>
<span class="k">if</span> <span class="n">m</span> <span class="o">==</span> <span class="n">nothing</span>
  <span class="n">println</span><span class="p">(</span><span class="s">&quot;not a comment&quot;</span><span class="p">)</span>
<span class="k">else</span>
  <span class="n">println</span><span class="p">(</span><span class="s">&quot;blank or comment&quot;</span><span class="p">)</span>
<span class="k">end</span>
</pre></div>
</div>
<p>If a regular expression does match, the value returned by <tt class="docutils literal"><span class="pre">match</span></tt> is a
<tt class="docutils literal"><span class="pre">RegexMatch</span></tt> object. These objects record how the expression matches,
including the substring that the pattern matches and any captured
substrings, if there are any. This example only captures the portion of
the substring that matches, but perhaps we want to capture any non-blank
text after the comment character. We could do the following:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span> <span class="o">=</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;^\s*(?:#\s*(.*?)\s*</span><span class="si">$</span><span class="s">|</span><span class="si">$</span><span class="s">)&quot;</span><span class="p">,</span> <span class="s">&quot;# a comment &quot;</span><span class="p">)</span>
<span class="n">RegexMatch</span><span class="p">(</span><span class="s">&quot;# a comment &quot;</span><span class="p">,</span> <span class="mi">1</span><span class="o">=</span><span class="s">&quot;a comment&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>When calling <tt class="docutils literal"><span class="pre">match</span></tt>, you have the option to specify an index at
which to start the search. For example:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span> <span class="o">=</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;[0-9]&quot;</span><span class="p">,</span><span class="s">&quot;aaaa1aaaa2aaaa3&quot;</span><span class="p">,</span><span class="mi">1</span><span class="p">)</span>
<span class="n">RegexMatch</span><span class="p">(</span><span class="s">&quot;1&quot;</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span> <span class="o">=</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;[0-9]&quot;</span><span class="p">,</span><span class="s">&quot;aaaa1aaaa2aaaa3&quot;</span><span class="p">,</span><span class="mi">6</span><span class="p">)</span>
<span class="n">RegexMatch</span><span class="p">(</span><span class="s">&quot;2&quot;</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span> <span class="o">=</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;[0-9]&quot;</span><span class="p">,</span><span class="s">&quot;aaaa1aaaa2aaaa3&quot;</span><span class="p">,</span><span class="mi">11</span><span class="p">)</span>
<span class="n">RegexMatch</span><span class="p">(</span><span class="s">&quot;3&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>You can extract the following info from a <tt class="docutils literal"><span class="pre">RegexMatch</span></tt> object:</p>
<ul class="simple">
<li>the entire substring matched: <tt class="docutils literal"><span class="pre">m.match</span></tt></li>
<li>the captured substrings as a tuple of strings: <tt class="docutils literal"><span class="pre">m.captures</span></tt></li>
<li>the offset at which the whole match begins: <tt class="docutils literal"><span class="pre">m.offset</span></tt></li>
<li>the offsets of the captured substrings as a vector: <tt class="docutils literal"><span class="pre">m.offsets</span></tt></li>
</ul>
<p>For when a capture doesn&#8217;t match, instead of a substring, <tt class="docutils literal"><span class="pre">m.captures</span></tt>
contains <tt class="docutils literal"><span class="pre">nothing</span></tt> in that position, and <tt class="docutils literal"><span class="pre">m.offsets</span></tt> has a zero
offset (recall that indices in Julia are 1-based, so a zero offset into
a string is invalid). Here&#8217;s is a pair of somewhat contrived examples:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span> <span class="o">=</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;(a|b)(c)?(d)&quot;</span><span class="p">,</span> <span class="s">&quot;acd&quot;</span><span class="p">)</span>
<span class="n">RegexMatch</span><span class="p">(</span><span class="s">&quot;acd&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="o">=</span><span class="s">&quot;a&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="o">=</span><span class="s">&quot;c&quot;</span><span class="p">,</span> <span class="mi">3</span><span class="o">=</span><span class="s">&quot;d&quot;</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span><span class="o">.</span><span class="n">match</span>
<span class="s">&quot;acd&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span><span class="o">.</span><span class="n">captures</span>
<span class="mi">3</span><span class="o">-</span><span class="n">element</span> <span class="n">Array</span><span class="p">{</span><span class="n">Union</span><span class="p">(</span><span class="n">SubString</span><span class="p">{</span><span class="n">UTF8String</span><span class="p">},</span><span class="kt">Nothing</span><span class="p">),</span><span class="mi">1</span><span class="p">}:</span>
 <span class="s">&quot;a&quot;</span>
 <span class="s">&quot;c&quot;</span>
 <span class="s">&quot;d&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span><span class="o">.</span><span class="n">offset</span>
<span class="mi">1</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span><span class="o">.</span><span class="n">offsets</span>
<span class="mi">3</span><span class="o">-</span><span class="n">element</span> <span class="n">Array</span><span class="p">{</span><span class="kt">Int64</span><span class="p">,</span><span class="mi">1</span><span class="p">}:</span>
 <span class="mi">1</span>
 <span class="mi">2</span>
 <span class="mi">3</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span> <span class="o">=</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;(a|b)(c)?(d)&quot;</span><span class="p">,</span> <span class="s">&quot;ad&quot;</span><span class="p">)</span>
<span class="n">RegexMatch</span><span class="p">(</span><span class="s">&quot;ad&quot;</span><span class="p">,</span> <span class="mi">1</span><span class="o">=</span><span class="s">&quot;a&quot;</span><span class="p">,</span> <span class="mi">2</span><span class="o">=</span><span class="n">nothing</span><span class="p">,</span> <span class="mi">3</span><span class="o">=</span><span class="s">&quot;d&quot;</span><span class="p">)</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span><span class="o">.</span><span class="n">match</span>
<span class="s">&quot;ad&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span><span class="o">.</span><span class="n">captures</span>
<span class="mi">3</span><span class="o">-</span><span class="n">element</span> <span class="n">Array</span><span class="p">{</span><span class="n">Union</span><span class="p">(</span><span class="n">SubString</span><span class="p">{</span><span class="n">UTF8String</span><span class="p">},</span><span class="kt">Nothing</span><span class="p">),</span><span class="mi">1</span><span class="p">}:</span>
 <span class="s">&quot;a&quot;</span>
 <span class="n">nothing</span>
 <span class="s">&quot;d&quot;</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span><span class="o">.</span><span class="n">offset</span>
<span class="mi">1</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">m</span><span class="o">.</span><span class="n">offsets</span>
<span class="mi">3</span><span class="o">-</span><span class="n">element</span> <span class="n">Array</span><span class="p">{</span><span class="kt">Int64</span><span class="p">,</span><span class="mi">1</span><span class="p">}:</span>
 <span class="mi">1</span>
 <span class="mi">0</span>
 <span class="mi">2</span>
</pre></div>
</div>
<p>It is convenient to have captures returned as a tuple so that one can
use tuple destructuring syntax to bind them to local variables:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">first</span><span class="p">,</span> <span class="n">second</span><span class="p">,</span> <span class="n">third</span> <span class="o">=</span> <span class="n">m</span><span class="o">.</span><span class="n">captures</span><span class="p">;</span> <span class="n">first</span>
<span class="s">&quot;a&quot;</span>
</pre></div>
</div>
<p>You can modify the behavior of regular expressions by some combination
of the flags <tt class="docutils literal"><span class="pre">i</span></tt>, <tt class="docutils literal"><span class="pre">m</span></tt>, <tt class="docutils literal"><span class="pre">s</span></tt>, and <tt class="docutils literal"><span class="pre">x</span></tt> after the closing double
quote mark. These flags have the same meaning as they do in Perl, as
explained in this excerpt from the <a class="reference external" href="http://perldoc.perl.org/perlre.html#Modifiers">perlre
manpage</a>:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">i</span>   <span class="n">Do</span> <span class="n">case</span><span class="o">-</span><span class="n">insensitive</span> <span class="n">pattern</span> <span class="n">matching</span><span class="o">.</span>

    <span class="n">If</span> <span class="n">locale</span> <span class="n">matching</span> <span class="n">rules</span> <span class="n">are</span> <span class="k">in</span> <span class="n">effect</span><span class="p">,</span> <span class="n">the</span> <span class="n">case</span> <span class="n">map</span> <span class="nb">is</span> <span class="n">taken</span>
    <span class="n">from</span> <span class="n">the</span> <span class="n">current</span> <span class="n">locale</span> <span class="k">for</span> <span class="n">code</span> <span class="n">points</span> <span class="n">less</span> <span class="n">than</span> <span class="mi">255</span><span class="p">,</span> <span class="n">and</span>
    <span class="n">from</span> <span class="n">Unicode</span> <span class="n">rules</span> <span class="k">for</span> <span class="n">larger</span> <span class="n">code</span> <span class="n">points</span><span class="o">.</span> <span class="n">However</span><span class="p">,</span> <span class="n">matches</span>
    <span class="n">that</span> <span class="n">would</span> <span class="n">cross</span> <span class="n">the</span> <span class="n">Unicode</span> <span class="n">rules</span><span class="o">/</span><span class="n">non</span><span class="o">-</span><span class="n">Unicode</span> <span class="n">rules</span> <span class="n">boundary</span>
    <span class="p">(</span><span class="n">ords</span> <span class="mi">255</span><span class="o">/</span><span class="mi">256</span><span class="p">)</span> <span class="n">will</span> <span class="n">not</span> <span class="n">succeed</span><span class="o">.</span>

<span class="n">m</span>   <span class="n">Treat</span> <span class="n">string</span> <span class="n">as</span> <span class="n">multiple</span> <span class="n">lines</span><span class="o">.</span>  <span class="n">That</span> <span class="nb">is</span><span class="p">,</span> <span class="n">change</span> <span class="s">&quot;^&quot;</span> <span class="n">and</span> <span class="s">&quot;</span><span class="si">$</span><span class="s">&quot;</span>
    <span class="n">from</span> <span class="n">matching</span> <span class="n">the</span> <span class="n">start</span> <span class="n">or</span> <span class="k">end</span> <span class="n">of</span> <span class="n">the</span> <span class="n">string</span> <span class="n">to</span> <span class="n">matching</span> <span class="n">the</span>
    <span class="n">start</span> <span class="n">or</span> <span class="k">end</span> <span class="n">of</span> <span class="n">any</span> <span class="n">line</span> <span class="n">anywhere</span> <span class="n">within</span> <span class="n">the</span> <span class="n">string</span><span class="o">.</span>

<span class="n">s</span>   <span class="n">Treat</span> <span class="n">string</span> <span class="n">as</span> <span class="n">single</span> <span class="n">line</span><span class="o">.</span>  <span class="n">That</span> <span class="nb">is</span><span class="p">,</span> <span class="n">change</span> <span class="s">&quot;.&quot;</span> <span class="n">to</span> <span class="n">match</span> <span class="n">any</span>
    <span class="n">character</span> <span class="n">whatsoever</span><span class="p">,</span> <span class="n">even</span> <span class="n">a</span> <span class="n">newline</span><span class="p">,</span> <span class="n">which</span> <span class="n">normally</span> <span class="n">it</span> <span class="n">would</span>
    <span class="n">not</span> <span class="n">match</span><span class="o">.</span>

    <span class="n">Used</span> <span class="n">together</span><span class="p">,</span> <span class="n">as</span> <span class="n">r</span><span class="s">&quot;&quot;</span><span class="n">ms</span><span class="p">,</span> <span class="n">they</span> <span class="k">let</span> <span class="n">the</span> <span class="s">&quot;.&quot;</span> <span class="n">match</span> <span class="n">any</span> <span class="n">character</span>
    <span class="n">whatsoever</span><span class="p">,</span> <span class="k">while</span> <span class="n">still</span> <span class="n">allowing</span> <span class="s">&quot;^&quot;</span> <span class="n">and</span> <span class="s">&quot;</span><span class="si">$</span><span class="s">&quot;</span> <span class="n">to</span> <span class="n">match</span><span class="p">,</span>
    <span class="n">respectively</span><span class="p">,</span> <span class="n">just</span> <span class="n">after</span> <span class="n">and</span> <span class="n">just</span> <span class="n">before</span> <span class="n">newlines</span> <span class="n">within</span> <span class="n">the</span>
    <span class="n">string</span><span class="o">.</span>

<span class="n">x</span>   <span class="n">Tells</span> <span class="n">the</span> <span class="n">regular</span> <span class="n">expression</span> <span class="n">parser</span> <span class="n">to</span> <span class="n">ignore</span> <span class="n">most</span> <span class="n">whitespace</span>
    <span class="n">that</span> <span class="nb">is</span> <span class="n">neither</span> <span class="n">backslashed</span> <span class="n">nor</span> <span class="n">within</span> <span class="n">a</span> <span class="n">character</span> <span class="n">class</span><span class="o">.</span> <span class="n">You</span>
    <span class="n">can</span> <span class="n">use</span> <span class="n">this</span> <span class="n">to</span> <span class="k">break</span> <span class="n">up</span> <span class="n">your</span> <span class="n">regular</span> <span class="n">expression</span> <span class="n">into</span>
    <span class="p">(</span><span class="n">slightly</span><span class="p">)</span> <span class="n">more</span> <span class="n">readable</span> <span class="n">parts</span><span class="o">.</span> <span class="n">The</span> <span class="sc">&#39;#&#39;</span> <span class="n">character</span> <span class="nb">is</span> <span class="n">also</span>
    <span class="n">treated</span> <span class="n">as</span> <span class="n">a</span> <span class="n">metacharacter</span> <span class="n">introducing</span> <span class="n">a</span> <span class="n">comment</span><span class="p">,</span> <span class="n">just</span> <span class="n">as</span> <span class="k">in</span>
    <span class="n">ordinary</span> <span class="n">code</span><span class="o">.</span>
</pre></div>
</div>
<p>For example, the following regex has all three flags turned on:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">r</span><span class="s">&quot;a+.*b+.*?d</span><span class="si">$</span><span class="s">&quot;</span><span class="n">ism</span>
<span class="n">r</span><span class="s">&quot;a+.*b+.*?d</span><span class="si">$</span><span class="s">&quot;</span><span class="n">ims</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">match</span><span class="p">(</span><span class="n">r</span><span class="s">&quot;a+.*b+.*?d</span><span class="si">$</span><span class="s">&quot;</span><span class="n">ism</span><span class="p">,</span> <span class="s">&quot;Goodbye,</span><span class="se">\n</span><span class="s">Oh, angry,</span><span class="se">\n</span><span class="s">Bad world</span><span class="se">\n</span><span class="s">&quot;</span><span class="p">)</span>
<span class="n">RegexMatch</span><span class="p">(</span><span class="s">&quot;angry,</span><span class="se">\n</span><span class="s">Bad world&quot;</span><span class="p">)</span>
</pre></div>
</div>
<p>Triple-quoted regex strings, of the form <tt class="docutils literal"><span class="pre">r&quot;&quot;&quot;...&quot;&quot;&quot;</span></tt>, are also
supported (and may be convenient for regular expressions containing
quotation marks or newlines).</p>
</div>
<div class="section" id="id3">
<h2>Byte Array Literals<a class="headerlink" href="#id3" title="Permalink to this headline">¶</a></h2>
<p>Another useful non-standard string literal is the byte-array string
literal: <tt class="docutils literal"><span class="pre">b&quot;...&quot;</span></tt>. This form lets you use string notation to express
literal byte arrays — i.e. arrays of <tt class="docutils literal"><span class="pre">Uint8</span></tt> values. The convention is
that non-standard literals with uppercase prefixes produce actual string
objects, while those with lowercase prefixes produce non-string objects
like byte arrays or compiled regular expressions. The rules for byte
array literals are the following:</p>
<ul class="simple">
<li>ASCII characters and ASCII escapes produce a single byte.</li>
<li><tt class="docutils literal"><span class="pre">\x</span></tt> and octal escape sequences produce the <em>byte</em> corresponding to
the escape value.</li>
<li>Unicode escape sequences produce a sequence of bytes encoding that
code point in UTF-8.</li>
</ul>
<p>There is some overlap between these rules since the behavior of <tt class="docutils literal"><span class="pre">\x</span></tt>
and octal escapes less than 0x80 (128) are covered by both of the first
two rules, but here these rules agree. Together, these rules allow one
to easily use ASCII characters, arbitrary byte values, and UTF-8
sequences to produce arrays of bytes. Here is an example using all
three:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">b</span><span class="s">&quot;DATA</span><span class="se">\xff\u2200</span><span class="s">&quot;</span>
<span class="mi">8</span><span class="o">-</span><span class="n">element</span> <span class="n">Array</span><span class="p">{</span><span class="kt">Uint8</span><span class="p">,</span><span class="mi">1</span><span class="p">}:</span>
 <span class="mh">0x44</span>
 <span class="mh">0x41</span>
 <span class="mh">0x54</span>
 <span class="mh">0x41</span>
 <span class="mh">0xff</span>
 <span class="mh">0xe2</span>
 <span class="mh">0x88</span>
 <span class="mh">0x80</span>
</pre></div>
</div>
<p>The ASCII string &#8220;DATA&#8221; corresponds to the bytes 68, 65, 84, 65.
<tt class="docutils literal"><span class="pre">\xff</span></tt> produces the single byte 255. The Unicode escape <tt class="docutils literal"><span class="pre">\u2200</span></tt> is
encoded in UTF-8 as the three bytes 226, 136, 128. Note that the
resulting byte array does not correspond to a valid UTF-8 string — if
you try to use this as a regular string literal, you will get a syntax
error:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="s">&quot;DATA</span><span class="se">\xff\u2200</span><span class="s">&quot;</span>
<span class="n">ERROR</span><span class="p">:</span> <span class="n">syntax</span><span class="p">:</span> <span class="n">invalid</span> <span class="n">UTF</span><span class="o">-</span><span class="mi">8</span> <span class="n">sequence</span>
</pre></div>
</div>
<p>Also observe the significant distinction between <tt class="docutils literal"><span class="pre">\xff</span></tt> and <tt class="docutils literal"><span class="pre">\uff</span></tt>:
the former escape sequence encodes the <em>byte 255</em>, whereas the latter
escape sequence represents the <em>code point 255</em>, which is encoded as two
bytes in UTF-8:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="n">julia</span><span class="o">&gt;</span> <span class="n">b</span><span class="s">&quot;</span><span class="se">\xff</span><span class="s">&quot;</span>
<span class="mi">1</span><span class="o">-</span><span class="n">element</span> <span class="n">Array</span><span class="p">{</span><span class="kt">Uint8</span><span class="p">,</span><span class="mi">1</span><span class="p">}:</span>
 <span class="mh">0xff</span>

<span class="n">julia</span><span class="o">&gt;</span> <span class="n">b</span><span class="s">&quot;\uff&quot;</span>
<span class="mi">2</span><span class="o">-</span><span class="n">element</span> <span class="n">Array</span><span class="p">{</span><span class="kt">Uint8</span><span class="p">,</span><span class="mi">1</span><span class="p">}:</span>
 <span class="mh">0xc3</span>
 <span class="mh">0xbf</span>
</pre></div>
</div>
<p>In character literals, this distinction is glossed over and <tt class="docutils literal"><span class="pre">\xff</span></tt> is
allowed to represent the code point 255, because characters <em>always</em>
represent code points. In strings, however, <tt class="docutils literal"><span class="pre">\x</span></tt> escapes always
represent bytes, not code points, whereas <tt class="docutils literal"><span class="pre">\u</span></tt> and <tt class="docutils literal"><span class="pre">\U</span></tt> escapes
always represent code points, which are encoded in one or more bytes.
For code points less than <tt class="docutils literal"><span class="pre">\u80</span></tt>, it happens that the UTF-8
encoding of each code point is just the single byte produced by the
corresponding <tt class="docutils literal"><span class="pre">\x</span></tt> escape, so the distinction can safely be ignored.
For the escapes <tt class="docutils literal"><span class="pre">\x80</span></tt> through <tt class="docutils literal"><span class="pre">\xff</span></tt> as compared to <tt class="docutils literal"><span class="pre">\u80</span></tt>
through <tt class="docutils literal"><span class="pre">\uff</span></tt>, however, there is a major difference: the former
escapes all encode single bytes, which — unless followed by very
specific continuation bytes — do not form valid UTF-8 data, whereas the
latter escapes all represent Unicode code points with two-byte
encodings.</p>
<p>If this is all extremely confusing, try reading <a class="reference external" href="https://web.archive.org/web/20141112182623/http://www.joelonsoftware.com/articles/Unicode.html">&#8220;The Absolute Minimum
Every Software Developer Absolutely, Positively Must Know About Unicode
and Character
Sets&#8221;</a>. It&#8217;s an
excellent introduction to Unicode and UTF-8, and may help alleviate some
confusion regarding the matter.</p>
</div>
<div class="section" id="version-number-literals">
<span id="man-version-number-literals"></span><h2>Version Number Literals<a class="headerlink" href="#version-number-literals" title="Permalink to this headline">¶</a></h2>
<p>Version numbers can easily be expressed with non-standard string literals of
the form <tt class="docutils literal"><span class="pre">v&quot;...&quot;</span></tt>. Version number literals create <tt class="docutils literal"><span class="pre">VersionNumber</span></tt> objects
which follow the specifications of <a class="reference external" href="http://semver.org">semantic versioning</a>,
and therefore are composed of major, minor and patch numeric values, followed
by pre-release and build alpha-numeric annotations. For example,
<tt class="docutils literal"><span class="pre">v&quot;0.2.1-rc1+win64&quot;</span></tt> is broken into major version <tt class="docutils literal"><span class="pre">0</span></tt>, minor version <tt class="docutils literal"><span class="pre">2</span></tt>,
patch version <tt class="docutils literal"><span class="pre">1</span></tt>, pre-release <tt class="docutils literal"><span class="pre">rc1</span></tt> and build <tt class="docutils literal"><span class="pre">win64</span></tt>. When entering a
version literal, everything except the major version number is optional,
therefore e.g.  <tt class="docutils literal"><span class="pre">v&quot;0.2&quot;</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">v&quot;0.2.0&quot;</span></tt> (with empty
pre-release/build annotations), <tt class="docutils literal"><span class="pre">v&quot;2&quot;</span></tt> is equivalent to <tt class="docutils literal"><span class="pre">v&quot;2.0.0&quot;</span></tt>, and so
on.</p>
<p><tt class="docutils literal"><span class="pre">VersionNumber</span></tt> objects are mostly useful to easily and correctly compare two
(or more) versions. For example, the constant <tt class="docutils literal"><span class="pre">VERSION</span></tt> holds Julia version
number as a <tt class="docutils literal"><span class="pre">VersionNumber</span></tt> object, and therefore one can define some
version-specific behaviour using simple statements as:</p>
<div class="highlight-julia"><div class="highlight"><pre><span class="k">if</span> <span class="n">v</span><span class="s">&quot;0.2&quot;</span> <span class="o">&lt;=</span> <span class="n">VERSION</span> <span class="o">&lt;</span> <span class="n">v</span><span class="s">&quot;0.3-&quot;</span>
    <span class="c"># do something specific to 0.2 release series</span>
<span class="k">end</span>
</pre></div>
</div>
<p>Note that in the above example the non-standard version number <tt class="docutils literal"><span class="pre">v&quot;0.3-&quot;</span></tt> is
used, with a trailing <tt class="docutils literal"><span class="pre">-</span></tt>: this notation is a Julia extension of the
standard, and it&#8217;s used to indicate a version which is lower than any <tt class="docutils literal"><span class="pre">0.3</span></tt>
release, including all of its pre-releases. So in the above example the code
would only run with stable <tt class="docutils literal"><span class="pre">0.2</span></tt> versions, and exclude such versions as
<tt class="docutils literal"><span class="pre">v&quot;0.3.0-rc1&quot;</span></tt>. In order to also allow for unstable (i.e. pre-release)
<tt class="docutils literal"><span class="pre">0.2</span></tt> versions, the lower bound check should be modified like this: <tt class="docutils literal"><span class="pre">v&quot;0.2-&quot;</span>
<span class="pre">&lt;=</span> <span class="pre">VERSION</span></tt>.</p>
<p>Another non-standard version specification extension allows to use a trailing
<tt class="docutils literal"><span class="pre">+</span></tt> to express an upper limit on build versions, e.g.  <tt class="docutils literal"><span class="pre">VERSION</span> <span class="pre">&gt;</span>
<span class="pre">&quot;v&quot;0.2-rc1+&quot;</span></tt> can be used to mean any version above <tt class="docutils literal"><span class="pre">0.2-rc1</span></tt> and any of its
builds: it will return <tt class="docutils literal"><span class="pre">false</span></tt> for version <tt class="docutils literal"><span class="pre">v&quot;0.2-rc1+win64&quot;</span></tt> and <tt class="docutils literal"><span class="pre">true</span></tt>
for <tt class="docutils literal"><span class="pre">v&quot;0.2-rc2&quot;</span></tt>.</p>
<p>It is good practice to use such special versions in comparisons (particularly,
the trailing <tt class="docutils literal"><span class="pre">-</span></tt> should always be used on upper bounds unless there&#8217;s a good
reason not to), but they must not be used as the actual version number of
anything, as they are illegal in the semantic versioning scheme.</p>
<p>Besides being used for the <tt class="docutils literal"><span class="pre">VERSION</span></tt> constant, <tt class="docutils literal"><span class="pre">VersionNumber</span></tt> objects are
widely used in the <tt class="docutils literal"><span class="pre">Pkg</span></tt> module, to specify packages versions and their
dependencies.</p>
</div>
</div>


          </div>
          <footer>
  
    <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation">
      
        <a href="functions.html" class="btn btn-neutral float-right" title="Functions"/>Next <span class="fa fa-arrow-circle-right"></span></a>
      
      
        <a href="complex-and-rational-numbers.html" class="btn btn-neutral" title="Complex and Rational Numbers"><span class="fa fa-arrow-circle-left"></span> Previous</a>
      
    </div>
  

  <hr/>

  <div role="contentinfo">
    <p>
    </p>
  </div>

  <a href="https://github.com/snide/sphinx_rtd_theme">Sphinx theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>
</footer>
        </div>
      </div>

    </section>

  </div>
  

  

    <script type="text/javascript">
        var DOCUMENTATION_OPTIONS = {
            URL_ROOT:'../',
            VERSION:'0.3.4',
            COLLAPSE_INDEX:false,
            FILE_SUFFIX:'.html',
            HAS_SOURCE:  true
        };
    </script>
      <script type="text/javascript" src="../_static/jquery.js"></script>
      <script type="text/javascript" src="../_static/underscore.js"></script>
      <script type="text/javascript" src="../_static/doctools.js"></script>
      <script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>

  

  
  
    <script type="text/javascript" src="../_static/js/theme.js"></script>
  

  
  
  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.StickyNav.enable();
      });
  </script>
   

</body>
</html>