Get Last Occurrence of a Substring in Arduino

Yash Sanghvi
Updated on 29-May-2021 13:28:49

869 Views

Just like indexOf() helps identify the first occurrence of a substring within a string, the lastIndexOf() function helps identify the last occurrence. This is because lastIndexOf() performs backward search, while indexOf() performs forward search.syntaxmyString.lastIndexOf(substr)Where substr is the substring to search for in myString. It can be a character or a string.Just like indexOf(), this function also accepts an optional from argument, in case you want the backward search to begin from a specific index. The syntax in that case is −SyntaxmyString.lastIndexOf(substr, from)Just like indexOf(), this function either returns the last index of the substring within the string, or it returns -1 if no match ... Read More

Get First Occurrence of Substring in Arduino

Yash Sanghvi
Updated on 29-May-2021 13:27:49

948 Views

The indexOf() function within Arduino scans a string from the beginning, and returns the first index of the specified substring within the string. The syntax is −SyntaxmyString.indexOf(substr)where substr is the substring to search for. It can be of type character or string.Optionally, you can provide a different starting point to begin the search from, in which case, the syntax is −SyntaxmyString.indexOf(substr, from)where from is the index from where the search should start. This function returns the index of the first occurrence of the substring within the string, or -1, if no match is found.Examplevoid setup() {    // put your setup code here, ... Read More

Fix Erroneous Binary Tree Using Python

Arnab Chakraborty
Updated on 29-May-2021 13:27:08

238 Views

Suppose, we are given a binary tree that has a problem; one of the node's right child pointer points to another node at the same level in the binary tree erroneously. So, to fix this problem, we have to find out the node that has this error and delete that node and its descendants except the node that it is erroneously pointing to. We return the root node of the fixed binary tree.So, if the input is likeWe can see that there is an erroneous link between 4 and 6. The right child pointer of 4 points to 6.then the ... Read More

Change the Root of a Binary Tree Using Python

Arnab Chakraborty
Updated on 29-May-2021 13:24:48

923 Views

Suppose, we are given a binary tree and a node that is situated at the leaf of the binary tree.We have to make the leaf node the root node of the binary tree. We can do it in the following way −If a node has a left child, it becomes the right child.A node's parent becomes its left child. In this process, the parent node's link to that node becomes null, so it will have only one child.The node structure of the tree is like below −TreeNode:    data:    left:    right:    parent: We have ... Read More

Find Lowest Common Ancestor of Binary Tree Using Python

Arnab Chakraborty
Updated on 29-May-2021 13:15:40

191 Views

Suppose, we are given a binary tree and are asked to find out the lowest common ancestor of all the nodes in the tree. The lowest common ancestor in a binary tree is the lowest node of which the nodes x1, x2, x3, ...., xn are descendants. A particular node can also be a descendant of itself. We have to find the node and return it as an output. The inputs are the root node of the tree and the list of nodes that we have to find the ancestor of.So, if the input is likeand the list of nodes ... Read More

Trim a String in Arduino

Yash Sanghvi
Updated on 29-May-2021 13:11:42

5K+ Views

Sometimes, a string can contain leading or trailing whitespaces. Arduino has a trim() function that removes all these leading/trailing whitespaces from the string.SyntaxString1.trim()Where String1 is the string that you need to trim. Please note that this function doesn’t return anything. String1 itself is modified.ExampleThe following example illustrates this −void setup() {    // put your setup code here, to run once:    Serial.begin(9600);    Serial.println();    String string1 = " Hello World! ";    Serial.println(string1);    string1.trim();    Serial.println(string1); } void loop() {    // put your main code here, to run repeatedly: }OutputThe Serial Monitor output is ... Read More

Check If Two Strings Are Equal While Ignoring Case in Arduino

Yash Sanghvi
Updated on 29-May-2021 13:11:04

924 Views

We know that String1.equals(String2) can be used to find out if String1 and String2 are equal in Arduino. However, this function is case sensitive. So, if there is a difference in the case of even a single character, this function will return false. A strategy that people use to perform case insensitive comparison of two strings is to convert both the strings to lower case and then compare. However, Arduino has a function to compare two strings while ignoring case. As you’d have guessed, the function is equalsIgnoreCase.ExampleAn example implementation is given below −void setup() {    // put your ... Read More

Semaphore and Mutex in FreeRTOS Using Arduino

Yash Sanghvi
Updated on 29-May-2021 13:09:18

2K+ Views

Semaphore and Mutex are tools/mechanisms to bring about synchronization between tasks in FreeRTOS. Often, two tasks need to share a resource, or one task needs to tell another that it is idle/waiting. Semaphores and Mutex help here. In this article, we will look at the concepts of semaphore and mutex.SemaphoreA semaphore is a synchronization mechanism between tasks. More specifically, it is a signalling mechanism. A task in the waiting state may receive a semaphore which tells it to do some work. Once the task has done that work, it will give the semaphore back. In practice, this is maintained by ... Read More

Change Default Location for Saving Sketches in Arduino IDE

Yash Sanghvi
Updated on 29-May-2021 13:08:43

1K+ Views

By default, on a Windows machine, Arduino saves all the sketches in C:\Users\\Documents\Arduino. Now, for whatever reason, you may want to change this default location. A common reason is that the C: has limited storage and you’d like to save sketches to a drive which has enough free space.In order to change the default location, go to File → Preferences.In the dialog box that opens up, the first input field is the Sketchbook location. Click on the ‘Browse’ button next to it and choose your desired path.After changing the path, click OK. Now, if you try to save a new ... Read More

Suspend and Resume Tasks in FreeRTOS Using Arduino

Yash Sanghvi
Updated on 29-May-2021 13:04:26

1K+ Views

If you wish to suspend a task in FreeRTOS, there is a function vTaskSuspend() that can be used. The syntax is −Syntaxvoid vTaskSuspend( TaskHandle_t xTaskToSuspend );As you can see, it takes the handle of the task to suspend as the argument and returns nothing. A suspended task can be resumed using vTaskResume(). The syntax is −Syntaxvoid vTaskResume( TaskHandle_t xTaskToResume );This again takes the handle of the task to be resumed, and returns nothing.In order to see an example, we will walk-through the code given in −https://exploreembedded.com/wiki/Task_Suspend_and_ResumeAs you can see, four Task handles are declared initially, and the tasks are created in the ... Read More

Advertisements