<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">\documentclass[onecolumn,letterpaper,11pt]{article}

%===================================================================
\input{common_latex/common_latex_packages}
\input{common_latex/common_latex_definitions}
\input{common_latex/common_latex_help_format}
%===================================================================

\begin{document}

\begin{labcover}
\labtitle{Help Topic: MOOS-IvP String Utilities}
\vspace{0.1in}
\labdate{Spring 2020}
\vspace{0.1in}
\labauth{Michael Benjamin, mikerb@mit.edu}
\labauth{Department of Mechanical Engineering}
\labauth{MIT, Cambridge MA 02139}
\labline
\end{labcover}

\wikidoc{file=Help.MIPStringUtils}
\wikidoc{auth=mikerb@mit.edu}

%======================================================================
\section*{MOOS-IvP String Utilities}
%======================================================================
\label{sec_string_parse}

The below describe a set of string utilities in the \var{MBUtils}
library distributed with MOOS-IvP. To use them, add \var{\#include
"MBUtils.h"} in your source code, and add the \var{mbutil} library to
the list of libraries your code links to, likely in your
local \var{CMakeLists.txt} file.

\pskip

These utilities are merely convenience functions. Often the C++
equivalent is either multiple lines of code, or relatively obtuse to
read. In any event you're welcome to take a look
in \var{moos-ivp/ivp/src/lib\_mbutil/MBUtils.cpp} to check out their
implementation.

%======================================================================
\subsection*{The \func{stripBlankEnds()} function}

The \func{stripBlankEnds()} function takes an STL string argument and
returns another STL string with leading and trailing white space
removed. White space is defined by either a blank space (ASCII 32) or
a tab (ASCII 09). The value of the string argument remains unchanged.

\vspace{0.08in}
\begin{fileverb}
 string stripBlankEnds(string);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 string original = "   Hello World! ";
 string modified = stripBlankEnds(original);
 cout &lt;&lt; "original: [" &lt;&lt; original &lt;&lt; "]" &lt;&lt; endl;
 cout &lt;&lt; "modified: [" &lt;&lt; modified &lt;&lt; "]" &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 original: [    Hello World! ]
 modified: [Hello World!];
\end{consoleverb}

%======================================================================
\subsection*{The \func{doubleToString()} function}

The \func{doubleToString()} function converts an argument of type
\var{double} to an STL string. It takes an optional integer argument
which in indicates the number of significant digits desired in the
resulting string. If the second argument is left out, the default is
2.

\vspace{0.08in}
\begin{fileverb}
 string doubleToString(double, int=2);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 double val  = 1234.56789;
 string str1 = doubleToString(val);
 string str2 = doubleToString(val, 4);
 cout &lt;&lt; "str1: " &lt;&lt; str1 &lt;&lt; endl;
 cout &lt;&lt; "str2: " &lt;&lt; str2 &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 str1: 1234.56
 str2: 1234.5678
\end{consoleverb}



%======================================================================
\subsection*{The \func{intToString()} function}

The \func{intToString()} function converts an argument of type
\var{int} to an STL string.

\vspace{0.08in}
\begin{fileverb}
 string intToString(int);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 int    val = -198;
 string str = intToString(val);
 cout &lt;&lt; "str: " &lt;&lt; str &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 str: -198
\end{consoleverb}


%======================================================================
\subsection*{The \func{uintToString()} function}

The \func{uintToString()} function converts an argument of type
\var{unsigned int} to an STL string.

\vspace{0.08in}
\begin{fileverb}
 string intToString(unsigned int);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 unsigned int val = 177;
 string str = uintToString(val);
 cout &lt;&lt; "str: " &lt;&lt; str &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 str: 177
\end{consoleverb}


%======================================================================
\subsection*{The \func{ulintToString()} function}

The \func{ulintToString()} function converts an argument of type
\var{unsigned long int} to an STL string.

\vspace{0.08in}
\begin{fileverb}
 string ulintToString(unsigned long int);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 unsigned long int val = 18446744073709551615;
 string str = ulintToString(val);
 cout &lt;&lt; "str: " &lt;&lt; str &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 str: 18446744073709551615
\end{consoleverb}


%======================================================================
\subsection*{The \func{boolToString()} function}

The \func{boolToString()} function converts an argument of type
\var{bool} to an STL string.

\vspace{0.08in}
\begin{fileverb}
 string boolToString(bool);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 bool   val = true;
 string str = boolToString(val);
 cout &lt;&lt; "str: " &lt;&lt; str &lt;&lt; endl;
 cout &lt;&lt; "str: " &lt;&lt; val &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 str: true
 str: 1
\end{consoleverb}


%======================================================================
\subsection*{The \func{strBegins()} function}

The \func{strBegins()} function determines if the first given STL string begins
with second STL string. An optional third Boolean argument indicates whether
the test should be case sensitive. This third argument defaults to \var{true}.

\vspace{0.08in}
\begin{fileverb}
 bool strBegins(string, string, bool=true);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 string str = "Hello World!";
 
 bool result1 = strBegins(str, "Hello");
 bool result2 = strBegins(str, "hello");
 bool result3 = strBegins(str, "hello", false);

 cout &lt;&lt; "result1: " &lt;&lt; boolToString(result1) &lt;&lt; endl;
 cout &lt;&lt; "result2: " &lt;&lt; boolToString(result2) &lt;&lt; endl;
 cout &lt;&lt; "result3: " &lt;&lt; boolToString(result3) &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 result1: true
 result2: false
 result3: true
\end{consoleverb}


%======================================================================
\subsection*{The \func{strEnds()} function}

The \func{strEnds()} function determines if the first given STL string ends
with second STL string. An optional third Boolean argument indicates whether
the test should be case sensitive. This third argument defaults to \var{true}.

\vspace{0.08in}
\begin{fileverb}
 bool strEnds(string, string, bool=true);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 string str = "Hello World!";
 
 bool result1 = strBegins(str, "World!");
 bool result2 = strBegins(str, "world!");
 bool result3 = strBegins(str, "world!", false);

 cout &lt;&lt; "result1: " &lt;&lt; boolToString(result1) &lt;&lt; endl;
 cout &lt;&lt; "result2: " &lt;&lt; boolToString(result2) &lt;&lt; endl;
 cout &lt;&lt; "result3: " &lt;&lt; boolToString(result3) &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 result1: true
 result2: false
 result3: true
\end{consoleverb}

%======================================================================
\subsection*{The \func{strContains()} function}

The \func{strContains(string, string)} function determines if the
first given STL string contains the second STL string. Pattern
matching is case sensitive.

\vspace{0.08in}
\begin{fileverb}
 bool strContains(string, string);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 string str = "Hello World!";
 
 bool result1 = strContains(str, "World");
 bool result2 = strContains(str, "hello");

 cout &lt;&lt; "result1: " &lt;&lt; boolToString(result1) &lt;&lt; endl;
 cout &lt;&lt; "result2: " &lt;&lt; boolToString(result2) &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 result1: true
 result2: false
\end{consoleverb}


%======================================================================
\subsection*{The \func{strContains()} function}

The \func{strContains(string, char)} function determines if the given
STL string contains the given character. Pattern matching is case
sensitive.

\vspace{0.08in}
\begin{fileverb}
 bool strContains(string, char);
\end{fileverb}

\vspace{0.1in}
\noindent
For example:

\vspace{0.08in}
\begin{fileverb}
 string str = "Hello World!";
 
 bool result1 = strContains(str, 'W');
 bool result2 = strContains(str, 'h');

 cout &lt;&lt; "result1: " &lt;&lt; boolToString(result1) &lt;&lt; endl;
 cout &lt;&lt; "result2: " &lt;&lt; boolToString(result2) &lt;&lt; endl;
\end{fileverb}

\vspace{0.1in}
\noindent
Produces:

\vspace{0.08in}
\begin{consoleverb}
 result1: true
 result2: false
\end{consoleverb}

\end{document}



</pre></body></html>