TSL
TSL

Reputation: 1

Strings in ASP?

I have some APSX code that I am trying to modify for a programmer that is out on medicaly leave. I am not an ASP guy, but rather C++

So what I want to do is delare a string, check the first 4 characters and if it is 'http' do something, if not, something else.

Here is what I have:

string strYT= Left(objFile, 4);

if (strYT=="http") {
    pnlYT.Visible = true;
    pnlIntro.Visible = false;
    pnlVideo.Visible = false;
}
else {
    pnlYT.Visible = false;
    pnlIntro.Visible = false;
    pnlVideo.Visible = true;

PrintText(objFile);
}

But I get errors like:

Compiler Error Message: CS0103: The name 'Left' does not exist in the class or namespace 'ASP.zen_aspx'

My googling turns up many examples of doing it just like this.....

Upvotes: 0

Views: 132

Answers (3)

Chase Florell
Chase Florell

Reputation: 47367

Here is is in VB

Dim str as String = "http://mywebsite.com"

If str.StartsWith("http://") Then
    ''# This is the true stuff
    pnlYT.Visible = True
    pnlIntro.Visible = False
    pnlVideo.Visible = False
Else
    ''# This is the false stuff
    pnlYT.Visible = False
    pnlIntro.Visible = False
    pnlVideo.Visible = True
End If

Here it is in C#

string str = "http://mywebsite.com";

if (str.StartsWith("http://")) {
    // This is the true stuff
    pnlYT.Visible = true;
    pnlIntro.Visible = false;
    pnlVideo.Visible = false;

} else {
    // This is the false stuff
    pnlYT.Visible = false;
    pnlIntro.Visible = false;
    pnlVideo.Visible = true;

}

Upvotes: 3

Seattle Leonard
Seattle Leonard

Reputation: 6776

string myString = getStringFromSomeWhere();
if(myString.StartsWith("http"))
{
    doSomething();
}
else
{
    doSomethingElse();
}

Upvotes: 0

MrSoundless
MrSoundless

Reputation: 1384

if (myString.StartsWith("http"))
   // do stuff
else
   // do other stuff

Upvotes: 0

Related Questions