

Whenever using eina we need to include it\+: 
\begin{DoxyCodeInclude}
\textcolor{preprocessor}{#include <stdio.h>}
\textcolor{preprocessor}{#include <\hyperlink{Eina_8h}{Eina.h}>}

\end{DoxyCodeInclude}


In our main function we declare(and initialize) some variables and initialize eina\+: 
\begin{DoxyCodeInclude}

\textcolor{keywordtype}{int} main(\textcolor{keywordtype}{int} argc EINA\_UNUSED, \textcolor{keywordtype}{char} **argv EINA\_UNUSED)
\{
   \textcolor{keywordtype}{char} *names = \textcolor{stringliteral}{"Calvin;Leoben;D'anna;Simon;Doral;Six;Daniel;Sharon"};
   \textcolor{keywordtype}{char} *str;
   \textcolor{keywordtype}{char} *tmp;
   \textcolor{keywordtype}{char} *prologue;
   \textcolor{keywordtype}{char} *part1 = \textcolor{stringliteral}{"The Cylons were created by man. They evolved. They rebelled."};
   \textcolor{keywordtype}{char} *part2 = \textcolor{stringliteral}{"There are many copies. And they have a plan."};
   \textcolor{keywordtype}{char} **arr;
   \textcolor{keywordtype}{int} i;

   \hyperlink{group__Eina__Main__Group_gabf448ada5bc81a07342b66c6f818ee5e}{eina\_init}();

\end{DoxyCodeInclude}


It's frequently necessary to split a string into its constituent parts, \hyperlink{group__Eina__String__Group_ga9001881b16684398e4e05bc537a8c1b6}{eina\+\_\+str\+\_\+split()} make's it easy to do so\+: 
\begin{DoxyCodeInclude}

   arr = \hyperlink{group__Eina__String__Group_ga9001881b16684398e4e05bc537a8c1b6}{eina\_str\_split}(names, \textcolor{stringliteral}{";"}, 0);
   \textcolor{keywordflow}{for} (i = 0; arr[i]; i++)
     printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, arr[i]);

\end{DoxyCodeInclude}


Another common need is to make a string uppercase or lowercase, so let's create a string and make it uppercase and then make it lowercase again\+: 
\begin{DoxyCodeInclude}

   free(arr[0]);
   free(arr);
   
   str = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 4);
   strcpy(str, \textcolor{stringliteral}{"bsd"});

   \hyperlink{group__Eina__String__Group_ga93d69385f153eba439faf9d5292af85f}{eina\_str\_toupper}((\textcolor{keywordtype}{char} **)&str);
   printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, str);
   \hyperlink{group__Eina__String__Group_ga1a0b1b2c6f082e19c9918fb2c428c849}{eina\_str\_tolower}(&str);
   printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, str);

\end{DoxyCodeInclude}


Next we use eina to check if our {\ttfamily names} string starts or ends with some values\+: 
\begin{DoxyCodeInclude}

   \textcolor{keywordflow}{if} (\hyperlink{group__Eina__String__Group_ga785b13b56a1f7c11086954ce676487b5}{eina\_str\_has\_prefix}(names, \textcolor{stringliteral}{"Calvin"}))
      printf(\textcolor{stringliteral}{"Starts with 'Calvin'\(\backslash\)n"});
   \textcolor{keywordflow}{if} (\hyperlink{group__Eina__String__Group_gafe3b6abced87d088ea993456e3d2db82}{eina\_str\_has\_suffix}(names, \textcolor{stringliteral}{"sharon"}))
      printf(\textcolor{stringliteral}{"Ends with 'sharon'\(\backslash\)n"});
   \textcolor{keywordflow}{if} (\hyperlink{group__Eina__String__Group_ga567e0b37fa2f30f95450ab5aa355445a}{eina\_str\_has\_extension}(names, \textcolor{stringliteral}{"sharon"}))
      printf(\textcolor{stringliteral}{"Has extension 'sharon'\(\backslash\)n"});

\end{DoxyCodeInclude}


When strings will be used in a terminal(or a number of other places) it necessary to escape certain characters that appear in them\+: 
\begin{DoxyCodeInclude}

   tmp = \hyperlink{group__Eina__String__Group_ga96760f2bf2d845b4abec0e95f08271bd}{eina\_str\_escape}(\textcolor{stringliteral}{"They'll start going ripe on us pretty soon."});
   printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, tmp);

\end{DoxyCodeInclude}


Much as we previously split a string we will now join two strings\+: 
\begin{DoxyCodeInclude}
   free(tmp);

   prologue = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 106);
   \hyperlink{group__Eina__String__Group_ga24948e6a270ad2e574dda5b97012cb41}{eina\_str\_join\_len}(prologue, 106, \textcolor{charliteral}{' '}, part1, strlen(part1), part2, strlen(part2));
   printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, prologue);

\end{DoxyCodeInclude}


With strlcpy() we can copy what portion of the {\ttfamily prologue} fits in {\ttfamily str} and be sure that it's still N\+U\+L\+L terminated\+: 
\begin{DoxyCodeInclude}

   \hyperlink{group__Eina__String__Group_ga6bda31d2e1b6d2737b7fe1784780cd2f}{eina\_strlcpy}(str, prologue, 4);
   printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, str);

\end{DoxyCodeInclude}


Since we are done with {\ttfamily prologue} and {\ttfamily str} we should free them\+: 
\begin{DoxyCodeInclude}

   free(prologue);
   free(str);

\end{DoxyCodeInclude}


Finally we see strlcat in action\+: 
\begin{DoxyCodeInclude}

   str = malloc(\textcolor{keyword}{sizeof}(\textcolor{keywordtype}{char}) * 14);
   sprintf(str, \textcolor{stringliteral}{"%s"}, \textcolor{stringliteral}{"cylons+"});
   \hyperlink{group__Eina__String__Group_ga6c9583940f9f6b3c886a19f22f398ff2}{eina\_strlcat}(str, \textcolor{stringliteral}{"humans"}, 14);
   printf(\textcolor{stringliteral}{"%s\(\backslash\)n"}, str);

\end{DoxyCodeInclude}


And then shut eina down and exit\+: 
\begin{DoxyCodeInclude}
   free(str);
   
   \hyperlink{group__Eina__Main__Group_ga6741fcaba116e31e96ce14dcfa03f568}{eina\_shutdown}();

   \textcolor{keywordflow}{return} 0;
\}

\end{DoxyCodeInclude}
 