Having issues with comparing string values with bluetooth device

I was just a french dude with a good idea so I made a test program to try it and now I can't continue cause it just doesn't work. Why? Any ideas?

There are probably unseen things like a trailing CR/LF or perhaps a null terminating character.

But really, the String class is...yuck. I wouldn't go there if it's not absolutely necessary (and it never is).

Well I tried a char value, but then it don't wants to compare and i don't know how do deal with it, can u help?

`if( val == "test")' did not work? perhaps you have a trailing CrLf that is being added to the string?

Images of code suck. Post code in code tags, please.

Yeah, but you didn't declare its size, so the compiler couldn't allocate size for it. That's a recipe for a crash. Secondly, have you checked what the return type of mySerial.read() is? If it's akin to regular Serial I would expect just a single char, but I never tried this with soft_serial.

Frankly I would just use char arrays and loop through them with a for-loop and compare them that way.

I don't really know what CrLf is, how can I deal with it? What should I do?

I tried to declare its size, and i'm on the same problem. It don't even want to transfer it. Can u help?

#include "SoftwareSerial.h"
SoftwareSerial mySerial(12,9); //mySerial(Tx,Rx)
char val[4];

void setup() {
  Serial.begin(9600);
  mySerial.begin(9600);
}

void loop() {
  if (mySerial.available()) {
    val=mySerial.read();
    Serial.print(val);
    if (val.equalsIgnoreCase("test")) {Serial.print("1");} //a simple comparaison that doesn't work, why? can someone help?
    else {Serial.print("0");}
  }
}

if you know the string starts with specified text try using startsWith and toUpperCase
however, I agree with @anon35827816 that String should be avoided
read characters into a char array and use functions from C library string.h to process it

Also ask yourself if you actually need to compare strings. If it's for instance for handling user input (type a command in serial monitor for instance), a single character often goes a long way. Also, there is ready-made code to do that sort of thing so you don't have to reinvent the wheel.

To be honest I don't really know if I have to. What I want is to send a text message with my phone and the program answer depending of what I sendt. For now I just try to make the program recognize what I send but it don't. How do you think I can do that?

When sending a text message, there's no rule written anywhere it needs to be long. You could send a single letter message to your Arduino and only look at that letter and then have the Arduino send back whatever it needs to. With a single letter you'd have the entire alphabet in upper and lower case + all numbers from 0-9 and that's not even counting special characters. I bet that's more than enough for the command set you have in mind.

You think it would be easier to code if it's with only one letter? Well I'm not against it but the problem still be the same: with a string it just doesn't work and with a char I can't even launch de program.
So I'll try with only one character, but how do I do that?

SoftwareSerial mySerial(12,9); //mySerial(Tx,Rx)
const char COMMAND_Y = "Y";

void setup() 
{
  mySerial.begin(9600);
  Serial.begin(9600);
}

void loop() {
    int input = mySerial.read(); //Reads one character; see https://www.arduino.cc/en/Reference/SoftwareSerialRead Will return -1 if no data available
    if (input > -1)
    {
        Serial.println(input);
        if (input == COMMAND_Y) {Serial.print("Yay!");} //Hurray!
        else {Serial.print("Nope.");} //:sadface:
    }
}

I didn't compile or test this, but this is the gist of it.
Note that there is no checking if serial input is available. Watch what happens if you enter a character on the Serial monitor; you'll actually see that more is received by the Arduino than just that single character. You also get '13' and '10', which stands for carriage return and line feed, which is the old-fashioned way of saying 'end of this line'.

Words such as "what does Crlf mean"
entered into an internet search engine could be enlightening.

Well I understand the most of it, but not the error occured: "invalid conversion from "const char*" to "char"". I tried to delete the const before char and it's still the same. Why?

My apologies; replace "Y" with 'Y'. Also add the include of the soft-serial library. Like so:

#include "SoftwareSerial.h"

SoftwareSerial mySerial(12,9); //mySerial(Tx,Rx)
const char COMMAND_Y = 'Y';

void setup() 
{
  mySerial.begin(9600);
  Serial.begin(9600);
}

void loop() {
    int input = mySerial.read(); //Reads one character; see https://www.arduino.cc/en/Reference/SoftwareSerialRead Will return -1 if no data available
    if (input > -1)
    {
        Serial.println(input);
        if (input == COMMAND_Y) {Serial.print("Yay!");} //Hurray!
        else {Serial.print("Nope.");} //:sadface:
    }
}

This seems to compile OK.

this sample code prompts the user to enter data in a format containing 'integer = 56'
if looks for a line which contains '"integer = ", if found attempts to parse an integer

// SERIAL: prompt user to enter an integer
void setup() {
    Serial.begin(115200);
}

void loop() {
  Serial.println("enter text 'integer = ' then an integer ? ");
  char text[100]={0};
  int index=-1;
  // read characters into char array
  do{
    char ch=Serial.read();
    if(ch!=-1) text[++index]=ch;
  }
  while(text[index]!='\n');
  Serial.print(text);
  // look for a line starting with 'integer = '
  if(strstr(text,"integer = ") != NULL){
     // if found parse integer
     Serial.print("integer entered = ");
     Serial.println(atoi(strstr(text,"integer = ") + 9));
  }
 }

a run gives

enter text 'integer = ' then an integer ? 
test string
enter text 'integer = ' then an integer ? 
integer = 99
integer entered = 99
enter text 'integer = ' then an integer ? 
test string ending in integer = 88
integer entered = 88

first string was "test string"
second was "integer = 99"
third was "test string ending in integer = 88"

Yeah this seems to work just fine so thanks a lot!

But this isn't in bluetooth? I tried to change it so it canrun with bluetooth devices but I only understand a half of your code so lots of errors...
But anyway @anon35827816 answered my questions and found a solution!
Thank you all for helping me!

I also made a test from the program you gave me, and it's working perfectly.
Thank you!

#include "SoftwareSerial.h"

SoftwareSerial mySerial(12,9); //mySerial(Tx,Rx)
const char testledbleuon = 'A';
const char testledbleuoff = 'B';

int ledbleu=8;

void setup() 
{
  Serial.begin(9600);
  mySerial.begin(9600);
  pinMode(ledbleu, OUTPUT);
}

void loop() {
  int input = mySerial.read(); //Reads one character; see https://www.arduino.cc/en/Reference/SoftwareSerialRead Will return -1 if no data available
  if (input > -1) {
    Serial.println(input);
    if (input == testledbleuon) {digitalWrite(ledbleu,HIGH);} //Hurray!
    if (input == testledbleuoff) {digitalWrite(ledbleu,LOW);} //Yay!
    else {Serial.print("Nope.");} //:sadface:
  }
delay(500);
}