String indexOf() and lastIndexOf() Method
Look for the first/last instance of a character in a string.
The String object indexOf() method gives you the ability to search for the first instance of a particular character value in a String. You can also look for the first instance of the character after a given offset. The lastIndexOf() method lets you do the same things from the end of a String.
1String stringOne = “<HTML><HEAD><BODY>”;
2int firstClosingBracket = stringOne.indexOf(‘>’);
In this case,
firstClosingBracket
equals 5, because the first
>
character is at position 5 in the String (counting the first character as 0). If you want to get the second closing bracket, you can use the fact that you know the position of the first one, and search from
firstClosingBracket + 1
as the offset, like so:
1stringOne = “<HTML><HEAD><BODY>”;
2int secondClosingBracket = stringOne.indexOf(‘>’, firstClosingBracket + 1 );
Source: String indexOf() and lastIndexOf() Method | Arduino Documentation | Arduino Documentation
String indexOf() and lastIndexOf() Method | Arduino Documentation | Arduino Documentation was last modified: December 27th, 2022 by