Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

String::replace buggy in certain cases #240

Closed as not planned
Closed as not planned
Assignees
per1234
@rspierce

Description

@rspierce

Description

replacing multiple occurrences of a string with a smaller string only works for an odd number of occurrences

Environment

Boards platform name

"Raspberry Pi Pico/RP2040" boards platform fromEarle F. Philhower, III

Boards platform version

Original report

Not specified

Last verified with

4.0.3

Code demonstrating problem

voidsetup() {  Serial.begin(9600);while (!Serial) {}// this code should remove all occurrences of "narf" from the string  String s ="narf";  Serial.println();  Serial.print("input: (");  Serial.print(s);  Serial.println(")");  s.replace("narf","");  Serial.print("result: (");  Serial.print(s);  Serial.println(")");  s ="narf narf";  Serial.println();  Serial.print("input: (");  Serial.print(s);  Serial.println(")");  s.replace("narf","");  Serial.print("result: (");  Serial.print(s);  Serial.println(")");}voidloop() {}

Serial monitor output:

input: (narf)result: ()input: (narf narf)result: (narf narf)

Additional information

In this code:

https://github.com/earlephilhower/ArduinoCore-API/blob/ece6e68f29c6f406a4434659bcbcfe558baaa3a9/api/String.cpp#L667-L671

while ((foundAt = strstr(readFrom, find.buffer)) !=NULL) {readFrom = foundAt + find.len;diff =0 - diff;size -= diff;}

line 669 (diff = 0 - diff;) should be above thewhile loop.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp