# Convert String to Integer

**URL:** <https://discourse.processing.org/t/convert-string-to-integer/2430>\
**Category:** Coding Questions\
**Created:** [August 7, 2018, 1:24am UTC](https://discourse.processing.org/t/convert-string-to-integer/2430 "2018-08-07T01:24:27Z")\
**Posts on this page:** 1\
**Showing post:** 12

<div class="post-metadata">

**Author:** ![glv](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/glv/32/18785_2.png) [@glv](https://discourse.processing.org/u/glv)\
**Post date:** [December 2, 2020, 11:40am UTC](https://discourse.processing.org/t/convert-string-to-integer/2430/12 "2020-12-02T11:40:31Z")

</div>

Hello,

Please format your code:  
[https://discourse.processing.org/faq#format-your-code](https://discourse.processing.org/faq#format-your-code)

> [@terryz](#):
>
> In order to get the int() function to work I had to remove 2 characters from the received data and I do not understand why when I expected it to be only one.

I used simulated data here and only had to remove 1 character which was the line feed ( ‘\n’).

I may be going off topic here.  
Start another one if you want to continue this.

Please provide a small snippet of the Arduino code and please format properly for the forum.

Some test code without the Arduino sending:

> **Test Code**
>
> ```auto
> String s;
> 
> void setup() 
> {
> //s = "v1m1v1m2v1m3v1m4/n";
> char LF = '\n'; // 1 character
> //Serial.println(“v1m123”); 
> s = "v1m123" + LF; // 6 characters + 1 character for LF (line feed)
> testData(s);
> }
> 
> void testData (String s)
> {
> String delim = "v1m";
> int l1;
> 
> //String deviceData = trim(s);
> String deviceData = s;
> 
> if(deviceData.indexOf(delim) == 0) 
> {    
> l1 = deviceData.length();
>     
> String Adata = deviceData.substring(3, l1-1); //-1 for LF
> //Extract only the numerical values, I do not know why I 
> //have to subtract 2 characters from the length instead of just 1 in order to get int() to work?????
> println(Adata);
> int sensorValue = int(Adata); 
> println(sensorValue);
> }
> else 
> {
> String debugMsg = deviceData;
> print(debugMsg);
> }
> }
> 
> ```

Here is another topic that may be of interest:

_[Serial plotter over bluetooth - #11 by glv](https://discourse.processing.org/t/serial-plotter-over-bluetooth/22378/11)_

Arduino can send data that is comma delimited (or other delimiter) and terminated with a line feed (or other [terminator](https://en.wikipedia.org/wiki/The_Terminator)) and Processing can receive and split it.

`:)`

---

_[View the full topic](https://discourse.processing.org/t/convert-string-to-integer/2430)._
