user51130: Lets say I have
String myString="AR0236";

I wish to extract the number 236 and assign it to an int. How can this be done?
P.S: I'me new to programming and I tried searching the forums for similar problems but surprising none of them worked for me!

user4143: There's multiple ways.
The String class (which TBH you should avoid) has some useful methods:

substring - extract part of a string as a new string
toInt - convert a string to an integer

So you can join them together:
int val = myString.substring(3).toInt();

That's the easy way.  Grab the string content from the 4th character (it's zero-based, so 3 is the 4th character) onwards, and convert it to an integer.
If you are avoiding String, as you should, then you are working with pointers.  For instance:
char myString[10]; // This is where your data gets stored
strcpy(myString, "AR0236"); // Let's put in some dummy data

int val = atoi(myString + 3);

myString + 3 gives you a new string pointer to a location that is 3 bytes further up in memory from myString - which equates to where the start of your number is.  Then convert that portion of the string to an integer.
The "easy" way consumes and makes a mess of your heap, since it's having to make a new String object and copy data into it. The "better" (second) way uses no more memory. It just converts a subset of the existing string directly.

51130: <p>Lets say I have</p>

<pre><code>String myString="AR0236";
</code></pre>

<p>I wish to extract the number 236 and assign it to an <code>int</code>. How can this be done?</p>

<p>P.S: I'me new to programming and I tried searching the forums for similar problems but surprising none of them worked for me!</p>
 4143: <p>There's multiple ways.</p>

<p>The String class (which TBH you should avoid) has some useful methods:</p>

<ul>
<li><a href="https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/substring/" rel="nofollow noreferrer">substring</a> - extract part of a string as a new string</li>
<li><a href="https://www.arduino.cc/reference/en/language/variables/data-types/string/functions/toint/" rel="nofollow noreferrer">toInt</a> - convert a string to an integer</li>
</ul>

<p>So you can join them together:</p>

<pre><code>int val = myString.substring(3).toInt();
</code></pre>

<p>That's the <em>easy</em> way.  Grab the string content from the 4th character (it's zero-based, so 3 is the 4th character) onwards, and convert it to an integer.</p>

<p>If you are avoiding String, as you should, then you are working with pointers.  For instance:</p>

<pre><code>char myString[10]; // This is where your data gets stored
strcpy(myString, "AR0236"); // Let's put in some dummy data

int val = atoi(myString + 3);
</code></pre>

<p><code>myString + 3</code> gives you a new string pointer to a location that is 3 bytes further up in memory from <code>myString</code> - which equates to where the start of your number is.  Then convert that portion of the string to an integer.</p>

<p>The "easy" way consumes and makes a mess of your heap, since it's having to make a new String object and copy data into it. The "better" (second) way uses no more memory. It just converts a subset of the existing string directly.</p>
