Solved

MyText Project

Posted on 2012-03-24
2
388 Views
Last Modified: 2012-03-24
I am getting this error. Can you help me with this issue?  Please be very specific with the discussion.  I am a student and in of need of information.  I have been given permission to get help with my projects from tutors.  

I must create a script that takes text that a user enters into a form field and converts it to title case capitalization.  Use a split()  method to split words in the string into an indexed array.  Then create a for loop that uses another split() method that splits each word in the elements of the indexed array into another another indexed array of characters.  Within the for loop, us he ToUpper() method to convert the first element in the second array (which represents the first characters in the word to uppercase) to uppercase, and then use the Join() method to rebuild the array of words in the text string.  Execute a final Join() method to convert the array of words back into a single text strin.  Save the project as TitleCase.
TitleCase.zip
error.docx
0
Comment
Question by:assaultkitty
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
Comment Utility
A NullReferenceException means that an object you are trying to use is not initialized.

If you put the cursor over myText when you get the error, you will probably see that its value is null. This means that your request did not return any value. Your "stringOfWords" element is probably empty.

Whenever you are retrieving information and expect that it could be empty, you need to check for the condition before using the returned value:
string myText = Request.Form["stringOfWords"];
string[] myTextArray;

if ( !( myText == null ) )
     myTextArray = myText.Split ( ' ' );
else
     // Output a message or deal with the situation any way you see fit

Open in new window

Further on, no need to split the string into an array of characters. A .NET string is already an array or characters. You can access them individually as myTextArray[0][0], myTextArray[0][1]...myTextArray[1][0], myTextArray[1][1]...
I leave the rest to you... you need to work a little in order to learn :-)
0
 

Author Closing Comment

by:assaultkitty
Comment Utility
string myText = Request.Form["stringOfWords"];
string[] myTextArray = myText.Split(' ');

This is the way that I did it.  Thanks for the hint.  I have problem with another issue. Thanks again.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now