Checking for a value in a string...

Results 1 to 2 of 2

Thread: Checking for a value in a string...

  1. #1
    Join Date
    Dec 1969

    Default Checking for a value in a string...

    In ASP I used to be able to check a string variable for value by doing something like...<BR><BR>If strText = "" Then<BR> strText = "Nothing"<BR>Else<BR> strText = "Something"<BR>End<BR><BR>...but in Asp.Net (VB) that does not work, using double "" marks does not work for detecting a NULL value. So I also tried...<BR><BR>If strText = Nothing Then<BR><BR>and<BR><BR>If Not strText &#060;&#062; Is Nothing Then<BR><BR>....but none of these work. I am looking for an easy way to see if a string has a value in it or if itis empty. Actually, I am not using a string I am using the text value of a text box like...<BR><BR>If Name.Text = Nothing Then<BR><BR>...and I am trying to see if that text box (an asp:textbox) has data in it or not.<BR><BR>Anybody have any ideas on this one???<BR><BR>Thanks,<BR>Matt<BR>

  2. #2
    Join Date
    Dec 1969

    Default Use the Length property

    Use the Length property of the String class:<BR><BR>If txtUsername.Length = 0 then<BR> &#039;the user didn&#039;t enter any information<BR>End If<BR><BR>On an asside, when doing form validation in ASP.NET, you really ought to let ASP.NET&#039;s validation controls do all of the work for you. See this article for more detail:<BR><BR><BR>Happy Programming!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts