<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE document PUBLIC "-//CNX//DTD CNXML 0.5 plus MathML//EN" "http://cnx.rice.edu/cnxml/0.5/DTD/cnxml_mathml.dtd">
<document xmlns="http://cnx.rice.edu/cnxml" xmlns:md="http://cnx.rice.edu/mdml/0.4" xmlns:m="http://www.w3.org/1998/Math/MathML" xmlns:bib="http://bibtexml.sf.net/" id="None">
  <name>String Functions</name>
  <metadata>
  <md:version>1.2</md:version>
  <md:created>2004/06/21 09:30:47 GMT-5</md:created>
  <md:revised>2007/07/19 10:08:50.074 GMT-5</md:revised>
  <md:authorlist>
      <md:author id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:author>
  </md:authorlist>

  <md:maintainerlist>
    <md:maintainer id="NationalInstruments">
      <md:firstname>National</md:firstname>
      
      <md:surname>Instruments</md:surname>
      <md:email>certification@ni.com</md:email>
    </md:maintainer>
    <md:maintainer id="lizzardg">
      <md:firstname>Elizabeth</md:firstname>
      
      <md:surname>Gregory</md:surname>
      <md:email>elizabeth.gregory@gmail.com</md:email>
    </md:maintainer>
    <md:maintainer id="mshiralkar05">
      <md:firstname>Malan</md:firstname>
      
      <md:surname>Shiralkar</md:surname>
      <md:email>mshiralkar05@hotmail.com</md:email>
    </md:maintainer>
    <md:maintainer id="harika">
      <md:firstname>Harika</md:firstname>
      
      <md:surname>Basana</md:surname>
      <md:email>ilsai@rice.edu</md:email>
    </md:maintainer>
  </md:maintainerlist>
  
  <md:keywordlist>
    <md:keyword>LabVIEW</md:keyword>
    <md:keyword>National Instrument</md:keyword>
    <md:keyword>string</md:keyword>
    <md:keyword>string function</md:keyword>
  </md:keywordlist>

  <md:abstract>In this lesson, you will learn how to use the String functions.</md:abstract>
</metadata>

  <content>
    <para id="p1">
      Use the String functions located on the <code>Functions&gt;&gt;All
      Functions&gt;&gt;String</code> palette to edit and manipulate strings
      on the block diagram. String functions include the following:
      <list id="p1l1" type="named-item"><item>
	  <name>String Length</name>
	  
	  Returns in <emphasis>length</emphasis> the number of
	  characters (bytes) <emphasis>string</emphasis>, including
	  space characters. For example, the <code>String Length</code> function
	  returns a <emphasis>length</emphasis> of <code>19</code> for
	  the following string: 
	  <code type="block">
	    The quick brown fox
	  </code>
	</item>
	<item>
	  <name>Concatenate Strings</name>

	  Concatenates input strings and 1D arrays of strings into a
	  single output string. For array inputs, this function
	  concatenates each element of the array. Add inputs to the
	  function by right-clicking an input and selecting <code>Add
	  Input</code> from the shortcut menu or by resizing the
	  function. For example, concatenate the previous string with
	  the following <!--<cnxn target="array">-->array<!--</cnxn>--> of strings:
	  <table frame="all" id="array">
	    <tgroup cols="5" align="left" colsep="1" rowsep="1">
	      <tbody valign="top">
		<row>
		  <entry align="center"><code>jumped</code></entry>
		  <entry align="center"><code>over</code></entry>
		  <entry align="center"><code>the</code></entry>
		  <entry align="center"><code>lazy</code></entry>
		  <entry align="center"><code>dog.</code></entry>
		</row>
	      </tbody>
	    </tgroup>
	  </table>
	  The <code>Concatenate Strings</code> function returns the following
	  string:
	  <code type="block">
	    The quick brown fox jumped over the lazy dog.
	  </code>
	</item>
	<item>
	  <name>String Subset</name>

	  Returns the <emphasis>substring</emphasis> of the input
	  <emphasis>string</emphasis> beginning at
	  <emphasis>offset</emphasis> and containing
	  <emphasis>length</emphasis> number of characters. The
	  <emphasis>offset</emphasis> of the first character in
	  <emphasis>string</emphasis> is <code>0</code>. For example,
	  if you use the previous string as the input, the
	  <code>String Subset</code> function returns the following
	  <emphasis>substring</emphasis> for an
	  <emphasis>offset</emphasis> of <code>4</code> and a
	  <emphasis>length</emphasis> of <code>5</code>: 
	  <code type="block">
	    quick
	  </code>
	</item>
	<item>
	  <name>Match Pattern</name>

	  Searches for <emphasis>regular expression</emphasis> in
	  <emphasis>string</emphasis> beginning at
	  <emphasis>offset</emphasis>, and if it finds a match, splits
	  <emphasis>string</emphasis> into three substrings. If no
	  match is found, <emphasis>match substring</emphasis> is
	  empty and <emphasis>offset past match</emphasis> is
	  <m:math><m:cn>-1</m:cn></m:math>. For example, use a
	  <emphasis>regular expression</emphasis> of <code>:</code>
	  and use the following string as the input:
	  <code type="block">
	    VOLTS DC: +1.22863E+1;
	  </code>
	  The <code>Match Pattern</code> function returns a <emphasis>before
	  substring</emphasis> of <code>VOLTS DC</code>, a
	  <emphasis>match substring</emphasis> of <code>:</code>, an
	  <emphasis>after substring</emphasis> of
	  <code>+1.22863E+1;</code>, and an <emphasis>offset past
	  match</emphasis> of <code>9</code>.
	</item>
      </list>
    </para>
    <section id="s1">
      <name>Converting Numeric Values to Strings with the Build Text
      Express VI</name>
      <para id="s1p1">
	Use the <code>Build Text</code> Express VI to convert numeric
	values into strings. The <code>Build Text</code> Express VI,
	located on the <code>Functions&gt;&gt;Output</code> palette,
	concatenates an input string. If the input is not a string,
	this Express VI converts the input into a string based on the
	configuration of the Express VI.
      </para>
      <para id="s1p2">
	When you place the <code>Build Text</code> Express VI on the
	block diagram, the <cnxn target="s1f1">Configure Build
	Text</cnxn> dialog box appears. The <cnxn target="s1f1">dialog box</cnxn> shows
	the Express VI configured to accept one input,
	<code>voltage</code>, and change it to a fractional number
	with a precision of 4. The input concatenates on the end of
	the string <code>Voltage is</code>. A space has been added to
	the end of the <code>Voltage is</code> string.
      </para>
      <figure id="s1f1">
	<media type="image/png" src="ConfigBuildText.png"/>
      </figure>
      <para id="s1p3">
	This configuration produces the block diagram shown in <cnxn target="s1f2"/>. A probe has been added to view the value of
	the output string. The <code>Build Text</code> Express VI
	concatenates the <code>Beginning Text</code> input, in this
	case the <code>voltage</code> value, at the end of the
	configured text.
      </para>
      <figure id="s1f2">
	<media type="image/png" src="BuildTextEx.png"/>
      </figure>
    </section>
    <section id="s2">
      <name>Converting Strings to Numeric Values with the Scan From
      String Function</name>
      <para id="s2p1">
	The <code>Scan From String</code> function converts a string containing
	valid numeric characters, such as <code>0-9</code>,
	<code>+</code>, <code>-</code>, <code>e</code>,
	<code>E</code>, and period (<code>.</code>), to a numeric
	value. This function scans the <emphasis>input
	string</emphasis> and converts the string according to
	<emphasis>format string</emphasis>. Use this function when you
	know the exact format of the input text. This function can
	scan <emphasis>input string</emphasis> into various data
	types, such as numeric or Boolean, based on the format
	string. Resize the function to increase the number of
	<emphasis>outputs</emphasis>.
      </para>
      <example id="s2ex1">
	<para id="s2ex1p1">
	  For example, use a <emphasis>format string</emphasis> of
	  <code>%f</code>, an <emphasis>initial search
	  location</emphasis> of <code>8</code>, and <code>VOLTS
	  DC+1.28E+2</code> as the <emphasis>input string</emphasis>,
	  to produce an output of <code>128</code>, as shown in the
	  block diagram shown in <cnxn target="s2ex1f1"/>. Change the
	  precision of the output by changing the precision of the
	  indicator.
	</para>
	<figure id="s2ex1f1">
	  <media type="image/png" src="ScanStringEx.png"/>
	</figure>
	<para id="s2ex1p2">
	  In <emphasis>format string</emphasis>, <code>%</code> begins
	  the format specifier and <code>f</code> indicates a
	  floating-point numeric with fractional format. Right-click
	  the function and select <code>Edit Scan String</code> from
	  the shortcut menu to create or edit a <emphasis>format
	  string</emphasis>. The <cnxn target="s2ex1f2">Edit Scan
	  String</cnxn> dialog box shows a configuration for the
	  format string <code>%4f</code>.
	</para>
	<figure id="s2ex1f2">
	  <media type="image/png" src="editformatex.png"/>
	</figure>
	<para id="s2ex1p3">
	  Refer to the <cite>LabVIEW Help</cite> for more information
	  about format specifier syntax.
	</para>
      </example>
    </section>
  </content> 
</document>
