A Text Replacing Program
Wow. As the calculator is put to the back burner for the moment, I've gotten time to work on other programs and get a post out at a decent time. Hopefully I'll be able to keep this up.
The class has been tasked to write a conditional character replacement program. The objective is to replace characters in a text file which aren't in specific words or adjacent to specific characters. This was apparently a difficult task for many, even myself. However, with some review from the other classmates in the class, I've created a method for replacing a certain character under specific conditions. The program can be found here on github.
The program works basically in the following way:
To be honest, this was my favourite program to do so far in the semester. Sure, the calculator was impressive for what I could do, but it took much effort and work to make possible to do some mildly simple things. This was a quick program that allowed me to do some playing with text, so I found it more amusing.
It seems I will be able to make an upload next week as well. I may also do something more interesting later on. So see you next time!
The class has been tasked to write a conditional character replacement program. The objective is to replace characters in a text file which aren't in specific words or adjacent to specific characters. This was apparently a difficult task for many, even myself. However, with some review from the other classmates in the class, I've created a method for replacing a certain character under specific conditions. The program can be found here on github.
The program works basically in the following way:
- Text is inputted from a file. Each line of text in the file is to put into a list as an item.
- The restricted words, restricted characters, the character to be replaced, and the character to replace, are inputted by the user within the console. The user can input multiple restricted words and characters, but only one character to be replaced and one character to replace.
- For each item, a line of text, in the list. We loop for each instance of the targeted character.
- We find the index of the first in the line of text
- We check if a restricted word is at the location of the character, or if an adjacent character is a restricted character
- If neither are true, the character is replaced
- All text in the line from the beginning to the index of the character is removed from this string and moved to a string containing the edited text
- With the first instance and all the text prior remove, we look for the next index and repeat this process
- Once the text has no more of the targeted character, the string containing the edited line is added to a new list containing each line of edited text
- We now repeat the process with the rest of the lines of text in the list
- After all lines of text have been edited, output a file containing all lines of the edited text
To be honest, this was my favourite program to do so far in the semester. Sure, the calculator was impressive for what I could do, but it took much effort and work to make possible to do some mildly simple things. This was a quick program that allowed me to do some playing with text, so I found it more amusing.
It seems I will be able to make an upload next week as well. I may also do something more interesting later on. So see you next time!
Comments
Post a Comment