Which Namespace contains NullToString ?

Error 1 The name 'NullToString' does not exist in the current context

I receive the above error compiling this email validating class:

using System;

using System.Collections.Generic;

using System.Text;

using System.Text.RegularExpressions;

using System.Net.Mail;

namespace WindowsApplication1

{

class Check

{

public static bool isEmail(string inputEmail)

{

inputEmail = NullToString(inputEmail);

string strRegex = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +

@"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +

@".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\] )$";

Regex re = new Regex(strRegex);

if (re.IsMatch(inputEmail))

return (true);

else

return (false);

}

}

}



Answer this question

Which Namespace contains NullToString ?

  • PawelWasilewski

    He's passing in a string which has not been declared anywhere. I assume that he's meant to pass in the string that was an input parameter.



  • PeacError

    There is no such thing as nulltostring. Best guess, it looks something like this:

    private string NullToString (string s)

    {

    return (s== null) "" : s;


    }



  • jreyes97

    Thank you very much for your answers. Trying the code from PJ I get this error now:

    Error 1 The name 'strRegex' does not exist in the current context


  • TJSR

    Null to String is at http://greatestcodesnippet.blogspot.com/2006/12/nulltoboolean-nulltocurrency.html


  • 20thCenturyBoy

    The method simply doesn't exist in the current contex, but your method should look like the example below. In .NET 2.0 you can use the String.IsNullOrEmpty method:


    public static bool isEmail(string inputEmail)
    {
    if( inputEmail == null || inputEmail.Lengt == 0 )
    {
    throw new ArgumentNullException( "inputEmail" );
    }

    const string expression = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
    @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
    @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\] )$";

    Regex regex = new Regex(strRegex);
    return regex.IsMatch(inputEmail);
    }




  • NickP001

    My best guess is that you are attempting to use the new string.IsNullOrEmpty method for parameter checking in your case.

    You would do something like

    if (string.IsNullOrEmpty(inputEmail))
    throw new ArgumentNullException("inputEmail"):

    // process as normal...

    Regards,

    Dave



  • GKRAO

    No reason to throw an exception: the function is called isEmail. Therefore, instead of throwing an exception if the string is null or empty, just return false, because the purpose of the function is to determine if a string is an email.


  • Dylan Smith

    Sorry, my bad. I wrote it out of the head. But here is a new example


    public static bool isEmail(string inputEmail)
    {
    if( inputEmail == null || inputEmail.Lengt == 0 )
    {
    throw new ArgumentNullException( "inputEmail" );
    }

    const string expression = @"^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}" +
    @"\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\" +
    @".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\] )$";

    Regex regex = new Regex(expression);
    return regex.IsMatch(inputEmail);
    }




  • Which Namespace contains NullToString ?