1. 可使用string库

#include<string>

String str1 = "#000P1000T2000!";
String str2 = "右左";

2. 字符串的拼接

#include<string>

String str1 = "#000P1000T2000!";
String str2 = "右左";
String str3 = "$DCR:600,600!";
String str4 = "7号反";
String p = str1 + ";"  + str2 + ";" + str3 + ";" + str4;

3. string字符串转换成const char *类型

#include<string>

String str1 = "#000P1000T2000!";
String str2 = "右左";
String str3 = "$DCR:600,600!";
String str4 = "7号反";
String p = str1 + ";"  + str2 + ";" + str3 + ";" + str4;
const char*  web_button_dict = p.c_str();

4. 使用strlen方法 获取const char *字符串的长度

#include<string>

String str1 = "#000P1000T2000!";
String str2 = "右左";
String str3 = "$DCR:600,600!";
String str4 = "7号反";
String p = str1 + ";"  + str2 + ";" + str3 + ";" + str4;
const char*  web_button_dict = p.c_str();

Serial.println(strlen((const char *)web_button_dict));

5. 读取esp32cam的sd卡中的内容并赋值给一个变量,并打印出来

#include "FS.h"
#include "SD_MMC.h"
#include "SPI.h"
#include<string>

String mystr = "";

void readFile(fs::FS &fs, const char * path){
    Serial.printf("Reading file: %s\n", path);

    File file = fs.open(path);
    if(!file){
        Serial.println("Failed to open file for reading");
        return;
    }

    Serial.println("Read from file: ");
    mystr = "";
    while(file.available()){
        mystr += char(file.read());
        //Serial.write(file.read());
    }
    const char*  web_button_dict = mystr.c_str();

    file.close();
    Serial.println(web_button_dict);
    /*
    //校验数据的准确性
    if(mystr.begin[0] =='$' && mystr.begin[10] =='!') {
        Serial.write(mystr);
    }
    */
}

void setup(){
    Serial.begin(115200);
    Serial.println();

    delay(2000);

    if(!SD_MMC.begin()){
        Serial.println("Card Mount Failed");
        return;
    }
    Serial.println();

    readFile(SD_MMC, "/web_button_config.txt");
}

void loop(){

}

 

6. 

 

posted on 2023-05-31 16:04  始终不够啊  阅读(16)  评论(0)    收藏  举报