如何在arduino中将字符串拆分为单词?

如何在arduino中将字符串拆分为单词?,arduino,Arduino,我在arduino有一根绳子 String name="apple orange banana"; 是否可以将每个项目存储在数组中arr 所以 arr[0]="apple" arr[1]="orange" ......etc 如果不将它们存储在单个变量中?如果您知道列表长度和每个列表项的最大字符数,您可以这样做 char arr[3][6] = {"apple", "orange", banana"}; 编辑:如果您正在寻找类似于字符串arr[3]的内容,您将无法获得它,因为C语言是如何

我在arduino有一根绳子

String name="apple orange banana";
是否可以将每个项目存储在数组中
arr

所以

arr[0]="apple" 
arr[1]="orange" ......etc

如果不将它们存储在单个变量中?

如果您知道列表长度和每个列表项的最大字符数,您可以这样做

char arr[3][6] = {"apple", "orange", banana"};
编辑:如果您正在寻找类似于
字符串arr[3]
的内容,您将无法获得它,因为C语言是如何管理内存的我相信这会对您有所帮助,您可以执行如下while循环:

int x;
String words[3];
while(getValue(name, ' ', x) != NULL){
     words[x] = getValue(name, ' ', x);
}
使用此功能:

// https://stackoverflow.com/questions/9072320/split-string-into-string-array
String getValue(String data, char separator, int index)
{
  int found = 0;
  int strIndex[] = {0, -1};
  int maxIndex = data.length()-1;

  for(int i=0; i<=maxIndex && found<=index; i++){
    if(data.charAt(i)==separator || i==maxIndex){
        found++;
        strIndex[0] = strIndex[1]+1;
        strIndex[1] = (i == maxIndex) ? i+1 : i;
    }
  }
  return found>index ? data.substring(strIndex[0], strIndex[1]) : "";
}
//https://stackoverflow.com/questions/9072320/split-string-into-string-array
String getValue(字符串数据、字符分隔符、int索引)
{
int=0;
int strIndex[]={0,-1};
int maxIndex=data.length()-1;
for(int i=0;i是否可以回答您的问题?