Results 1 to 4 of 4

Thread: blank session variables return  

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982

    blank session variables return  

    I have a couple of session string variables.

    In some cases they will be empty strings and I want them to return an empty string but they return   (non breaking space). Is there some quick way, may be a built in function to convert the   to and empty string (without an if statement)


    Things I do when I am bored: DotNetable

  2. #2
    Addicted Member
    Join Date
    Nov 2001
    Location
    Yewston, Texis
    Posts
    240
    You didn't say what you were programming in. I'll assume VB.Net:

    Code:
      Dim regEx, str1               ' Create variables.
      sessionStr1 = "& nbsp;"
      Set regEx = New RegExp            ' Create regular expression.
      regEx.Pattern = "& nbsp;"           ' Set pattern.
      regEx.IgnoreCase = True            ' Make case insensitive.
    
      'Once the above is set up, you should be able to do the following repeatedly
      ReplaceTest = regEx.Replace(sessionStr1, "")   ' Make replacement.
    The above uses regular expressions which some might argue is overkill. Perhaps, but if you don't know about regular expressions, and you want to gain a competitive edge, learning about them now will definitely help. In a nutshell, regular expressions let you do wildcard matching of strings in wild ways.

    HTH,
    cudabean

  3. #3
    I wonder how many charact
    Join Date
    Feb 2001
    Location
    Savage, MN, USA
    Posts
    3,704
    I'm more curious to know why or how your strings are returning &nbsp?

    Any session variables I use as strings I always test against String.Empty on the code behind:
    VB Code:
    1. If me.Session.Item(0) = String.Empty ...

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Oct 1999
    Location
    England
    Posts
    982
    After looking back at my code I found out why it was happening.

    I am setting the value of the session variable with the value in a datagrid cell. As the database field is null it is defaulting to   at bind time.

    I have however made a note of string.empty and now use that, thanks nemaroller.


    Things I do when I am bored: DotNetable

Posting Permissions

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



Click Here to Expand Forum to Full Width