=================
String Processing
=================

.. Modified: 2019-10-25/13:20-0400 btiffin
.. Copyright 2016 Brian Tiffin
.. GPL 3.0+ :ref:`license`
.. This file is part of the Unicon Programming documentation.

.. image:: images/unicon.png
   :align: center

.. only:: html

    :ref:`genindex`
    :floatright:`<a href="http://unicon.sourceforge.net/">Unicon</a>`

Unicon String Processing
========================

.. index::
   pair: string; scanning
   single: string scanning

.. _string scanning:

String Scanning
---------------
``Unicon`` string scanning is a very powerful computational feature of the
language.  With roots dating back to :ref:`SNOBOL`, string scanning was added
to :ref:`Icon` by the team lead by :ref:`Ralph` as a modernization of the
pattern matching features of ``SNOBOL``.  ``Unicon`` has gone full circle and
starting with the release 13 beta builds, ``SNOBOL`` :doc:`patterns` are
actually part of the system again.  And to add to the already rich options,
:ref:`regular expressions` are also available now.  A trifecta.

Scanning
........
String scanning syntax is based on the scanning operator :ref:`binop\?`.

.. sourcecode:: unicon

    expr1 ? expr2

Where the result of |expr1| sets a scanning environment, :ref:`&subject` and
:ref:`&pos` specifying the subject characters and current position of the
scanning cursor.  |expr2| can be any valid Unicon expression, usually a
sequence, and can range from simple to very complex selection and side effect
operations.

A "simple" scan.  Find Waldo.

.. literalinclude:: examples/simple-scan.icn
   :language: unicon
   :start-after: ##+

.. only:: html

    .. rst-class:: rightalign

        :download:`examples/simple-scan.icn`

Sample run:

.. command-output:: unicon -s simple-scan.icn -x
   :cwd: examples

A middling scan.  Find name from command line (or Waldo).

.. literalinclude:: examples/middling-scan.icn
   :language: unicon
   :start-after: ##+

.. only:: html

    .. rst-class:: rightalign

        :download:`examples/middling-scan.icn`

Sample run:

.. command-output:: unicon -s middling-scan.icn -x
   :cwd: examples

.. todo:: add string scanning samples

See: :doc:`patterns` for a more on scanning.

.. only:: html
   
   ..

   --------

   :ref:`genindex` | Previous: :doc:`tools` | Next: :doc:`patterns`

   |