arduino / arduino/ArduinoCore-API

Arduino String class: features missing (feature request)

Open
#152 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
306
Forks
150
PR merge metrics
No merged PRs in 30d

Description

hi,
for Arduino C++ Strings some features are missing:
.readStringUntil(EOL) or perhaps a new .readln(): to read an entire textline all at once until end of line, discarding any EoL/CR
(e.g., text lines may have \n or \r\n at EoL, so readStringUntil('\n') or readStringUntil('\r') may fail or mess it up)

additionally also helpful:
.insert(substr, pos, len)
.delete(pos, len)
and especially
.TokenArg(token, delimiter1, delimiter2) // edit: optionally also just named .arg()
// returns the value of a token, e.g. for a String containing analog=1234;
`String myArg = myString.TokenArg("analog", "=", ";") ` would return 1234 as a String.

OTOH, IMO .compareTo() is ambiguous, it returns +/-/0 for after/before/ident but completely unclear if or what when neither and they are completely different. Better if it returned NAN/-1/0/+1 for notIn/smaller/ident/bigger.

PS,
just recalled that the WebServer lib provides a method `.arg()` which works somehow like the requested `String.TokenArg()` functionality:
```
int Analog1=0;
String myArg = webserver.arg("analog");
if (myArg != "") {
Analog1 = myArg.toInt();
}
```
That could be also used as a pattern for a String class TokenArg function.

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names Arduino C++ String methods but provides no files or tests. Start by reviewing the existing String class and compareTo/read behavior, then clarify the requested API and newline semantics with maintainers. Done means the scope and behavior of the proposed changes are agreed before implementation.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
embedded-iot
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.