This was my first project at JustIT.
There are five functions; WORD COUNT, SLANG CONVERTER, WORD FREQ, SEARCH and ANALYSE.
They work correctly however I've thought of a way to fix a small problem that the WORD COUNT function used to have.
When the paragraph of text is split into a string-array of sentences, an extra empty element is created at the end.
I have a new idea on how to improve this and it should make the code more readable.
NOTE: Here is a link to the project - Text Editor
As you can see from the image the paragraph is split by the full stop (".") and this creates five elements hence "senArray.Length = 5". Ideally this should equal four.
The last element (senArray[4]) is blank.
NOTE - I'm testing this small segment of code in rextester (an online IDE).
Now I've added some more formatting to the string to get rid of the space in front of the full stop (Replace(". ",".")).
text1.Split(splitOn.ToCharArray(), StringSplitOptions.RemoveEmptyEntries.
I came accross the line of code above whilst watching videos on PluralSight.
Stage 1: Remove punctuation and split paragraphs into sentences.
Stage 2: Create array to hold number of words in each sentence.
Stage 3: For-loop: Go through each sentence. Split sentence by white-space. Count words cumulatively. Store number of words in sentence. Print sentence number and number of words in sentence.
Stage 4: Print total nuber of sentences and total number of words in paragraph.
I have updated my code and it works correctly.
I have updated my GitHub and the screenshot shows most of the code.
When the word-count button is clicked, Button1_Click executes.
If the input textbox is blank, the user is prompted to type something.
Then the four stages described previously are the same.
Here is a link to the GitHub code - Text Editor GitHub
formatStringClass.formatString();
In three out of the five functions there is a small block of code that repeats. So I created a class and a method for it.
I created a class named "formatStringClass" and created a method (formatString).
When the funciton is called it recieves a string, gets rid of the punctuaion and then returns it.
I did this because of the single responsibilty design principle (SOLID) and because it makes the code easier to read.
There are three textboxes in the text editor.
If the user types the name of a colour or its hex value, types the string "changeColor" in the search-textbox and clicks on the ANALYSE TEXT button then the colour of the font in all three textboxes gets set to the colour that was entered by the user.
I wanted to make this feature hidden because I was just experimenting with Javascript and how it can manipulate CSS.
When the ANALYSE TEXT button is clicked it triggers the inputColor function.
If the search textbox (TextBox3) contains the value "changeColor", the text value in the input textbox gets saved to a variable (ccc). This value is also stored in sessionStorage[myKey].
The setColor function executes and then the searchbox (TextBox3) is cleared.
The setColor function sets the color of the font in all three of the textboxes to the value that was entered.
When the RESET button is clicked it triggers the JavaScript function.
It sets the font colour of the textboxes to "white".