user57320: I have a string:
string s="digitalWrite(8,LOW);"

Is there any way to run it as a code?

user7508: This is actually pretty simple:
if (s == "digitalWrite(8,LOW);") {
    digitalWrite(8,LOW);
}

Obviously, it will not work is s contains any other string... If you
want something more general, that is able to interpret a wide range of
possible commands, you will have to define a language, and write an
interpreter for that language. From the example you give, it seems you
would like your language to look like C++. This is most likely a bad
design choice. If you want an interpreter that understands the whole C++
language: forget it. You will never fit something this big into an
Arduino Uno.
Here is, for inspiration, a very simple interpreter I
wrote that understand the following commands:
mode <pin> <mode>: pinMode()
read <pin>: digitalRead()
aread <pin>: analogRead()
write <pin> <value>: digitalWrite()
awrite <pin> <value>: analogWrite()
echo <value>: set echo off (0) or on (1)

You can use it a basis for writing your custom interpreter. Otherwise
you can do a Web search for “Arduino interpreter”: you should be able to
find interpreters implementing a wide variety of languages, including
compact binary languages (Firmata), Forth (another one),
Lisp, Basic, and even a C-like language.

57320: <p>I have a string:</p>

<pre><code>string s="digitalWrite(8,LOW);"
</code></pre>

<p>Is there any way to run it as a code?</p>
 7508: <p>This is actually pretty simple:</p>

<pre class="lang-cpp prettyprint-override"><code>if (s == "digitalWrite(8,LOW);") {
    digitalWrite(8,LOW);
}
</code></pre>

<p>Obviously, it will not work is <code>s</code> contains any other string... If you
want something more general, that is able to interpret a wide range of
possible commands, you will have to define a language, and write an
interpreter for that language. From the example you give, it seems you
would like your language to look like C++. This is most likely a bad
design choice. If you want an interpreter that understands the whole C++
language: forget it. You will never fit something this big into an
Arduino Uno.</p>

<p>Here is, for inspiration, <a href="https://gist.github.com/edgar-bonet/607b387260388be77e96" rel="nofollow noreferrer">a very simple interpreter</a> I
wrote that understand the following commands:</p>

<pre><code>mode &lt;pin&gt; &lt;mode&gt;: pinMode()
read &lt;pin&gt;: digitalRead()
aread &lt;pin&gt;: analogRead()
write &lt;pin&gt; &lt;value&gt;: digitalWrite()
awrite &lt;pin&gt; &lt;value&gt;: analogWrite()
echo &lt;value&gt;: set echo off (0) or on (1)
</code></pre>

<p>You can use it a basis for writing your custom interpreter. Otherwise
you can do a Web search for “Arduino interpreter”: you should be able to
find interpreters implementing a wide variety of languages, including
compact binary languages (<a href="https://github.com/firmata/arduino" rel="nofollow noreferrer">Firmata</a>), <a href="https://flashforth.com/" rel="nofollow noreferrer">Forth</a> (<a href="https://github.com/tschaer/tofish" rel="nofollow noreferrer">another one</a>),
<a href="http://www.ulisp.com/" rel="nofollow noreferrer">Lisp</a>, <a href="https://github.com/robinhedwards/ArduinoBASIC" rel="nofollow noreferrer">Basic</a>, and even <a href="https://n.mtng.org/ele/arduino/iarduino.html" rel="nofollow noreferrer">a C-like language</a>.</p>
