Tutorial.StringCharacters History

Hide minor edits - Show changes to output

May 02, 2012, at 03:56 PM by Scott Fitzgerald -
Changed line 52 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/8.Strings/StringCharacters/StringCharacters.ino lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/08.Strings/StringCharacters/StringCharacters.ino lang=arduino tabwidth=4:)
November 16, 2011, at 04:25 AM by Scott Fitzgerald -
Changed line 52 from:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/8.Strings/StringCharacters/StringCharacters.pde lang=arduino tabwidth=4:)
to:
(:source http://arduino.cc/en/pub/code/master/build/shared/examples/8.Strings/StringCharacters/StringCharacters.ino lang=arduino tabwidth=4:)
September 19, 2010, at 11:29 PM by Christian Cerrito -
Added lines 71-72:

September 19, 2010, at 11:29 PM by Christian Cerrito -
Added lines 57-58:

September 19, 2010, at 11:28 PM by Christian Cerrito -
Changed lines 34-35 from:
!!!Circuit
to:
September 19, 2010, at 11:28 PM by Christian Cerrito -
Deleted lines 7-8:
!!!Hardware Required
No external hardware is required.
Changed lines 37-47 from:
There is no circuit for this example.
to:
!!!Hardware Required:

* Arduino Board

!!!Circuit
(:div class=circuit :)
There is no circuit for this example, though your Arduino must be connected to your computer via USB.

%height=250px%[[Attach:Arduino_bb.png | Attach:Arduino_bb.png]]
[-image developed using [[http://www.fritzing.org |Fritzing]]. For more circuit examples, see the [[http://fritzing.org/projects/|Fritzing project page]] -]
September 16, 2010, at 10:39 PM by Tom Igoe -
Changed line 15 from:
[@
to:
(:source lang=arduino tabwidth=4:)
Changed line 19 from:
@]
to:
(:sourceend:)
Changed line 25 from:
[@
to:
(:source lang=arduino tabwidth=4:)
Changed line 31 from:
to:
(:source
August 01, 2010, at 05:15 PM by Tom Igoe -
Added lines 1-61:
''Examples > Strings''

!!!String Character Functions

The [[Reference/StringObject|String]] functions @@charAt()@@ and @@setCharAt()@@ are used to get or set the value of a character at a given position in a String.

(:div class=BOM :)
!!!Hardware Required
No external hardware is required.
(:divend:)

At their simplest, these functions help you search and replace a given character. For example, the following replaces the colon in a given String with an equals sign:

(:div class=code :)
[@
String reportString = "SensorReading: 456";
int colonPosition = reportString.indexOf(':');
reportString.setCharAt(colonPosition, '=');
@]
(:divend:)

Here's an example that checks to see if the first letter of the second word is 'B':

(:div class=code :)
[@
String reportString = "Franklin, Benjamin";
int spacePosition = reportString.indexOf(' ');
if (reportString.charAt(spacePosition + 1) == 'B') {
Serial.println("You might have found the Benjamins.")
}
@]
(:divend:)

'''Caution:'''
If you try to get the @@charAt@@ or try to @@setCharAt()@@ a value that's longer than the String's length, you'll get unexpected results. If you're not sure, check to see that the position you want to set or get is less than the string's length using the @@length()@@ function.
!!!Circuit

(:div class=circuit :)
There is no circuit for this example.
(:divend:)

!!!Code
(:div class=code :)

(:source

Share