Solved

MyText Project

Posted on 2012-03-24
2
394 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 40

Accepted Solution

by:
Jacques Bourgeois (James Burger) earned 500 total points
ID: 37761063
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
ID: 37761335
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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