比较和更改Arduino Nodemcu中字符串的内容

发布于 2025-02-05 17:03:56 字数 238 浏览 1 评论 0原文

我有一个字符串,但我似乎无法更改其内容。 我想检查字符串是否包含“ Relay1”,并且是否应该将其内容更改为“ 15”。

if (inputMessage1 == "relay1") {
    inputMessage1.replace("relay1", "15");
}

我还尝试了“ InputMessage.comPareto()”,但没有尝试。 因此,这真的很简单,但我正在四处走动。

I have a string but i don't seem to be able to change its content.
I want to check if the string contains "relay1" and if it does it should change its content to "15".

if (inputMessage1 == "relay1") {
    inputMessage1.replace("relay1", "15");
}

I have also tried with 'inputMessage.compareto()' but nothing.
So this is suppose to be really simple but i am going around and around.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

债姬 2025-02-12 17:03:57

您可以检查这两个平等是否等于:

if (inputMessage1.equals("relay1")) {
    inputMessage1.replace("relay1", "15");
}

如果您要检查包含文本是否,则可以使用以下方式:

if (inputMessage1.indexOf("relay1") > 0) {
    inputMessage1.replace("relay1", "15");
}

You can check if both equals like:

if (inputMessage1.equals("relay1")) {
    inputMessage1.replace("relay1", "15");
}

if do you want to check if contains text or not then you can use like:

if (inputMessage1.indexOf("relay1") > 0) {
    inputMessage1.replace("relay1", "15");
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文