# Cannot declare strings?

**URL:** <https://community.particle.io/t/cannot-declare-strings/19999>\
**Category:** General\
**Created:** [February 12, 2016, 6:18pm UTC](https://community.particle.io/t/cannot-declare-strings/19999 "2016-02-12T18:18:06Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![randykarr](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@randykarr](https://community.particle.io/u/randykarr)\
**Post date:** [February 12, 2016, 6:18pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/1 "2016-02-12T18:18:06Z")

</div>

I must be missing something very basic here ?  
Using Particle Build, whenever I try and declare a String it does not “highlight” the word String ? Or string ?  
And I get an error when I verify.

I can declare integers just fine, int is highlighted, but not Int - which is fine no caps  
Also I can declare char just fine, char is automatically highlighted

Looking at Strings in Particle Reference docs: It looks just like Arduino IDE, which works fine.

What am I missing.  
thanks much

---

<div class="post-metadata">

**Author:** ![Ric](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/ric/32/514_2.png) [@Ric](https://community.particle.io/u/Ric)\
**Post date:** [February 12, 2016, 6:38pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/2 "2016-02-12T18:38:38Z")

</div>

String, with a capital “S” should work, but it does not get highlighted, even though it shows it blue in the docs. Are you trying this in a .ino file? If not, then you should include “application.h” at the top of your file. What error are you getting?

---

<div class="post-metadata">

**Author:** ![randykarr](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@randykarr](https://community.particle.io/u/randykarr)\
**Post date:** [February 12, 2016, 7:35pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/3 "2016-02-12T19:35:12Z")

</div>

Yes, writing .ino in Build

I added application.h and the string now appears to be defined.  
Strange, I then took application.h out and it still works (like Build remembered it)

Still one problem,

The code below works fine (reads from serial 2 and outputs to serial 0)

```cpp
#include "Serial2/Serial2.h"
#include "application.h"

String myString = "test string";

// EXAMPLE USAGE
void setup()
{
  Serial.begin(9600);
  Serial2.begin(9600);

}

void loop()
{
  // read from port 2, send to port 0:
  if (Serial2.available())
   { 
     int inByte = Serial2.read();
     int a = inByte;
     Serial.write(a);
     // Serial.write(myString);
          
      }
}

```

However, if I add the Serial.write(myString); which was commented out I get the error below

```nohighlight
serialtest.cpp:22:27: error: no matching function for call to 'USBSerial::write(String&)'
   if (Serial2.available())
                           ^

```

---

<div class="post-metadata">

**Author:** ![ScruffR](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/scruffr/32/6952_2.png) [@ScruffR](https://community.particle.io/u/ScruffR)\
**Post date:** [February 12, 2016, 8:17pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/4 "2016-02-12T20:17:38Z")

</div>

What hardware (Core or Photon) and what firmware version are you targeting?

`Serial.print(myString)` should always work, but with a current version `Serial.write(myString)` should work too - alternatively you could try `Serial.write((const char*)myString)` or `Serial.write(myString.c_str())` too.

---

<div class="post-metadata">

**Author:** ![randykarr](https://avatars.discourse-cdn.com/v4/letter/r/a88e4f/32.png) [@randykarr](https://community.particle.io/u/randykarr)\
**Post date:** [February 12, 2016, 9:28pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/5 "2016-02-12T21:28:47Z")

</div>

Core hardware, Serial.print(myString) WORKS…

So looks like a version problem to me…

Thanks loads ALL, back on track…

Randy

---

<div class="post-metadata">

**Author:** ![Quark](https://avatars.discourse-cdn.com/v4/letter/q/5e9695/32.png) [@Quark](https://community.particle.io/u/Quark)\
**Post date:** [December 6, 2018, 8:35am UTC](https://community.particle.io/t/cannot-declare-strings/19999/6 "2018-12-06T08:35:30Z")

</div>

Hi - I’m having a similar problem. Can’t seem to declare String, IDE does not turn the writing blue. And particle.publish() using my sting will not send back an event.

Does anyone have any more thoughts on this?

Cheers.

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [December 6, 2018, 9:17am UTC](https://community.particle.io/t/cannot-declare-strings/19999/7 "2018-12-06T09:17:13Z")

</div>

> [@Quark](#):
>
> Can’t seem to declare String, IDE does not turn the writing blue.

> [@Ric](#):
>
> String, with a capital “S” should work, but it does not get highlighted, even though it shows it blue in the docs.

> [@Quark](#):
>
> Does anyone have any more thoughts on this?

Yes

> [@ScruffR](#):
>
> What hardware (Core or Photon) and what firmware version are you targeting?

Also

> [@Ric](#):
>
> Are you trying this in a .ino file? If not, then you should include “application.h” at the top of your file. What error are you getting?

---

<div class="post-metadata">

**Author:** ![Quark](https://avatars.discourse-cdn.com/v4/letter/q/5e9695/32.png) [@Quark](https://community.particle.io/u/Quark)\
**Post date:** [December 6, 2018, 10:10am UTC](https://community.particle.io/t/cannot-declare-strings/19999/8 "2018-12-06T10:10:59Z")

</div>

Have made sure I have capital ‘S’

I am using an .ino file but tried putting application.h at top anyway - code compiled but did not make any difference.

I’m using an Electron - latest version.

There is no error produced - it just doesn’t seem to recognise ‘String’ declaration…

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [December 6, 2018, 10:36am UTC](https://community.particle.io/t/cannot-declare-strings/19999/9 "2018-12-06T10:36:23Z")

</div>

> [@Quark](#):
>
> There is no error produced

Then I'm confused, if there's no error, everything should be running. How are you verifying it's not working?

Would you mind giving us a share link from the web IDE so we can have a look at your code, or paste it here?

---

<div class="post-metadata">

**Author:** ![Quark](https://avatars.discourse-cdn.com/v4/letter/q/5e9695/32.png) [@Quark](https://community.particle.io/u/Quark)\
**Post date:** [December 6, 2018, 12:42pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/12 "2018-12-06T12:42:49Z")

</div>

```auto
//#include “application.h”

int pin2 = D2;
int pin7 = D7;
int switchState = 0;

//unsigned long openMillis;
//unsigned long closedMillis;
//unsigned long closedTime;
int openMillis;
int closedMillis;
int closedTime;
int cond;
int Count = 0;

void setup() {
pinMode(pin2,INPUT);
pinMode(pin7,OUTPUT);
//Serial.begin(9600);
}

void loop() {

switchState = digitalRead(pin2);

if (switchState == LOW) {
    openMillis = millis(); 
    digitalWrite(pin7,HIGH);

    if (cond == 1) {
    
    Count = Count+1;
    
    String data = String(Count) + "," + String(closedTime);
    Particle.publish("Time",data);
    
    
    cond = 0;
    }
    
    else{
    // do nothing
    }

    }
    
else{
    digitalWrite(pin7,LOW);
    closedMillis = millis();
    closedTime = closedMillis - openMillis;
    cond = 1;
    
}
delay(1000);
}

```

---

<div class="post-metadata">

**Author:** ![Quark](https://avatars.discourse-cdn.com/v4/letter/q/5e9695/32.png) [@Quark](https://community.particle.io/u/Quark)\
**Post date:** [December 6, 2018, 12:46pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/13 "2018-12-06T12:46:26Z")

</div>

In the IDE String is not being declared / highlighted Blue. Code just take a push of a button into Pin3. Logic turns off LED on Pin7. When button is released some data will be published, num times pressed, how long.

As an aside I’m also trying to publish lots of data in one event. Particle.publish() only seems to handle Stings. Welcome any advice on publishing arrays of data.

---

<div class="post-metadata">

**Author:** ![Moors7](https://sea2.discourse-cdn.com/flex026/user_avatar/community.particle.io/moors7/32/588_2.png) [@Moors7](https://community.particle.io/u/Moors7)\
**Post date:** [December 6, 2018, 1:20pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/14 "2018-12-06T13:20:28Z")

</div>

> [@Quark](#):
>
> In the IDE String is not being declared / highlighted Blue.

Well, hence this:

> [@Ric](#):
>
> it does not get highlighted, even though it shows it blue in the docs.

the fact that it's not lighting up blue doesn't mean it's not working. It's just that the syntax highlighting of the Web IDE shows it as being something 'special'.

But other than that, I'm not quite seeing how you determine how it's not working? If it compiles and flashes, it ought to work, save for logical errors.

What doe you expect it to do, and what doesn't it do? And what _does_ it do?

---

<div class="post-metadata">

**Author:** ![Quark](https://avatars.discourse-cdn.com/v4/letter/q/5e9695/32.png) [@Quark](https://community.particle.io/u/Quark)\
**Post date:** [December 7, 2018, 6:49pm UTC](https://community.particle.io/t/cannot-declare-strings/19999/15 "2018-12-07T18:49:41Z")

</div>

Just sat down to re-try this bit of code. Seems to be working now. Thanks for your reply!
