Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To answer the question you actually asked, String objects are very powerful and they can do exactly what you ask. If you limit your parsing rules directly from the input, your code becomes less flexible, less reusable, and slightly convoluted.</p> <p>Strings have a method called indexOf() which allows you to search for the index in the String's character array of a particular character. If the character is not found, the method should return -1. A second parameter can be added to the function call to indicate a starting point for the search. In your case, since your delimiters are commas, you would call:</p> <pre><code>int commaIndex = myString.indexOf(','); // Search for the next comma just after the first int secondCommaIndex = myString.indexOf(',', commaIndex + 1); </code></pre> <p>Then you could use that index to create a substring using the String class's substring() method. This returns a new String beginning at a particular starting index, and ending just before a second index (Or the end of a file if none is given). So you would type something akin to:</p> <pre><code>String firstValue = myString.substring(0, commaIndex); String secondValue = myString.substring(commaIndex + 1, secondCommaIndex); String thirdValue = myString.substring(secondCommaIndex + 1); // To the end of the string </code></pre> <p>Finally, the integer values can be retrieved using the String class's undocumented method, toInt():</p> <pre><code>int r = firstValue.toInt(); int g = secondValue.toInt(); int b = thirdValue.toInt(); </code></pre> <p>More information on the String object and its various methods can be found int the <a href="http://arduino.cc/en/Reference/StringObject" rel="nofollow noreferrer">Arduino documentation</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload