Mastery 25 (strings)

Hello everybody:

For this mastery I will show you three pictures of three different programs I created in which I used strings. Let´s remember that strings represent series of characters, so take a look at these programs, and see how I used them.

In the first one, I used a string to define the first line in the .txt file I took the data from. After that I used the substring statement to  select only the part of the data I nedded of each line, and finally I just converted the string to a float using the atoi function.

 

In the next program I used a string for the same purposes that in the first one. The string defines the first line of the file, but by using a loop, every single line in the file is eventually checked. In this case I didn´t use the substring statement because I needed all the data in each line (the line was jus a number). As I did in the first program, at the end I just converted the string to a float by using the atoi function. 

,   

 

In the last program, I also defined the first line of the program as a string, but in this case the program has to identify how many times the word “banana” appears within the file. I had to use the function “transform” to change all capital letters to non-capital so the program would count “BanAna”,  “BANANA” “banana” or any other mix. The last thing I had to do was to use the function find in order to check for the word I nedded. 

As you can see, strings are not that complicated to use and they can be used to many different aplications. I hope you guys find this useful.

Thanks for reading.

 

CC BY 4.0 Mastery 25 (strings) by Jesús Tostado is licensed under a Creative Commons Attribution 4.0 International License.

Comments are closed.