Loading...
Poll
Question: Find a bug in WString.h
Bug correction - 0 (0%)
Correction - 2 (100%)
Total Voters: 2

Pages: [1]   Go Down
Author Topic: Report bug... WString Replace("xxx","yyy")  (Read 414 times)
0 Members and 2 Guests are viewing this topic.
Offline Offline
Newbie
*
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I.

please replace this line in the WString.h file

void replace(const String& find, const String& replace);
by
void replace(const String &find, const String &replace);

Tanks...
Logged

Offline Offline
Sr. Member
****
Posts: 378
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

They're the same thing to the compiler, and the version used looks nicer.
Logged

Seattle, WA USA
Online Online
Brattain Member
*****
Posts: 22888
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
They're the same thing to the compiler, and the version used looks nicer.
I'll agree with the first half of your statement, but I prefer the * and & to go with the variable, not the type.

int* a, b;
looks like the type is int* for both a and b, but it isn't. a is an int pointer, but b is an int.

int *a, b;
makes it clear that the type is int, and that a is a pointer while b isn't.

In my opinion.
Logged

Offline Offline
Newbie
*
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I.
Probably it works with another complier.

by the way, the example "string remove" also need correction. replace return void...
Code:
/*
  String replace()
 
 Examples of how to replace characters or substrings of a string
 
 created 27 July 2010
 by Tom Igoe
 
 http://arduino.cc/en/Tutorial/StringReplace
 
 This example code is in the public domain.
 */

void setup() {
  Serial.begin(9600);
  Serial.println("\n\nString  replace:");
}

void loop() {
  String stringOne = "<html><head><body>";
  Serial.println(stringOne);
  // replace() changes all instances of one substring with another:
  stringOne.replace("<","</");
  String stringTwo = stringOne;
  Serial.println(stringTwo);

  // you can also use replace() on single characters:
  String normalString = "bookkeeper";
  Serial.println("normal: " + normalString);
  normalString.replace('o', '0');
  String leetString = normalString;
  leetString.replace('e', '3');
  leetString = leetString;
  Serial.println("l33tspeak: " + leetString);

  // do nothing while true:
  while(true);
}
Logged

Pages: [1]   Go Up
Print
 
Jump to: