【问题标题】:How to split a specific part from a string in C++ arduino如何在 C++ arduino 中从字符串中拆分特定部分
【发布时间】:2018-12-02 19:04:34
【问题描述】:

如何在 C++ arduino 中从字符串中拆分特定部分?,

String str = "Hello?"

如果我想删除“?”该怎么办?在字符串中?

【问题讨论】:

  • 你试过阅读the officila Arduino reference吗?尤其是关于String的部分。
  • 是的,我做到了,但没有帮助
  • std::string::erase()。对于 C 样式的字符数组,您可以用 '\0' 覆盖 '?'
  • @ThomasMatthews 如果我有一个类似于 "11.432.531" 的字符串并且可以是任何随机数,我需要做什么才能用 \n 替换这些点?跨度>
  • 参见std::string::find,它将返回您正在搜索的字符的位置。然后简单地执行分配:my_string[position] = '\n';.

标签: c++ split arduino


【解决方案1】:

将字符串作为数组读取并使用循环查找它 if(str[x] == "?"){str[x] = 0;}

【讨论】:

  • 为什么要从std::string 后退一步到字符数组?即使截断是需要的(我会使用'\0' 而不是0,因为这是字符数据),std::string 也可以轻松完成。
猜你喜欢
  • 1970-01-01
  • 2022-01-04
  • 2023-03-05
  • 1970-01-01
  • 2018-01-11
  • 2016-04-24
  • 2021-07-20
相关资源
最近更新 更多