DevDiary



Project 01: Text Editor

ASP.NET, Webforms

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



Unit Test 01

Word Count Function (Problem)

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).



Unit Test 02

Word Count Function (Solution)

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.



Unit Test 03

Stages (Word Count Function)

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.



GitHub

Code Updated and Published

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



Method 01

Call Function


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.



Method 02

Single Responsibility

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.



JavaScript and CSS (01)

Change Text Colour

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.



JavaScript and CSS (02)

inputColor()

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.



JavaScript and CSS (03)

setColor()

The setColor function sets the color of the font in all three of the textboxes to the value that was entered.



JavaScript and CSS (04)

resetColor()

When the RESET button is clicked it triggers the JavaScript function.

It sets the font colour of the textboxes to "white".