Baldie47
Baldie47

Reputation: 1274

Check if session value contains string

I have a condition based on a session value:

if session("legal_entity")="entity1" then

now, this works well, but only if the value in "session("legal_entity")" is "entity1".

how do I do if the value of session("legal_entity") is "someText.entity1.someOtherText".

this would be to check for the sub string. I tried the following:

if session("legal_entity").Contains("entity1") then

but of course doesn't work. What solution could I use to simply ask for the sub string inside the session value?

Upvotes: 1

Views: 937

Answers (1)

ArunPratap
ArunPratap

Reputation: 5030

you can do that after converting to string like this

 if(Convert.ToString(Session["legal_entity"]) == "entity1")

or you can also cast the (session) object reference to string:

 if (((string)Session["legal_entity"]) == "entity1")

or if you want to use contains method than do that like this

if (Convert.ToString(Session["legal_entity"]).Contains("entity1"))
    {
       //your code here
    }

Upvotes: 2

Related Questions