From fc944ff979dbbd49a57722fe2d1d2acf47312eb4 Mon Sep 17 00:00:00 2001 From: Jesse Morgan Date: Thu, 20 Oct 2011 22:16:19 -0700 Subject: Inital commit... halfway through the project --- .../ATS_StringIndexOfMemory.pde | 102 +++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 libraries/ArduinoTestSuite/examples/ATS_StringIndexOfMemory/ATS_StringIndexOfMemory.pde (limited to 'libraries/ArduinoTestSuite/examples/ATS_StringIndexOfMemory') diff --git a/libraries/ArduinoTestSuite/examples/ATS_StringIndexOfMemory/ATS_StringIndexOfMemory.pde b/libraries/ArduinoTestSuite/examples/ATS_StringIndexOfMemory/ATS_StringIndexOfMemory.pde new file mode 100644 index 0000000..08fcc99 --- /dev/null +++ b/libraries/ArduinoTestSuite/examples/ATS_StringIndexOfMemory/ATS_StringIndexOfMemory.pde @@ -0,0 +1,102 @@ +//************************************************************************ +//* Arduino Test Example Skeleton +//* (C) 2010 by Rick Anderson +//* Open source as per standard Arduino code +//* +//************************************************************************ +//* Oct 16, 2010 Started on String Test +//************************************************************************ + +#include "WProgram.h" +#include "HardwareSerial.h" +#include + +//************************************************************************ +void setup() +{ + char testName[64]; + int startMemoryUsage; + /* + * Create variable for the tests. + */ + + + String stringOne; + int firstClosingBracket; + int firstOpeningBracket; + int secondOpeningBracket; + int secondClosingBracket; + int bodyTag; + int firstListItem; + int secondListItem; + int lastOpeningBracket; + int lastListItem; + int lastParagraph; + int secondLastGraf; + + /*; + * initiate the test run + */ + startMemoryUsage = ATS_GetFreeMemory(); + ATS_begin("Arduino", "String Memory Test"); + // indexOf() returns the position (i.e. index) of a particular character + // in a string. For example, if you were parsing HTML tags, you could use it: + stringOne = ""; + firstClosingBracket = stringOne.indexOf('>'); + Serial.println("The index of > in the string " + stringOne + " is " + firstClosingBracket); + + stringOne = ""; + secondOpeningBracket = firstClosingBracket + 1; + secondClosingBracket = stringOne.indexOf('>', secondOpeningBracket ); + Serial.println("The index of the second > in the string " + stringOne + " is " + secondClosingBracket); + + // you can also use indexOf() to search for Strings: + stringOne = ""; + bodyTag = stringOne.indexOf(""); + Serial.println("The index of the body tag in the string " + stringOne + " is " + bodyTag); + + stringOne = "
  • item
  • item
  • item
"; + firstListItem = stringOne.indexOf("
  • "); + secondListItem = stringOne.indexOf("item", firstListItem + 1 ); + Serial.println("The index of the second list item in the string " + stringOne + " is " + secondClosingBracket); + + // lastIndexOf() gives you the last occurrence of a character or string: + lastOpeningBracket = stringOne.lastIndexOf('<'); + Serial.println("The index of the last < in the string " + stringOne + " is " + lastOpeningBracket); + + lastListItem = stringOne.lastIndexOf("
  • "); + Serial.println("The index of the last list item in the string " + stringOne + " is " + lastListItem); + + + // lastIndexOf() can also search for a string: + stringOne = "

    Lorem ipsum dolor sit amet

    Ipsem

    Quod

    "; + lastParagraph = stringOne.lastIndexOf("