Asp.net ASP中的字符串?
我有一些APSX代码,我正试图修改为一个程序员,是在医疗休假。我不是一个ASP的家伙,而是一个C++ 所以我想做的是,如果是一个字符串,检查前4个字符,如果是“http”,做一些事情,如果不是,做一些其他事情 以下是我所拥有的:Asp.net ASP中的字符串?,asp.net,string,Asp.net,String,我有一些APSX代码,我正试图修改为一个程序员,是在医疗休假。我不是一个ASP的家伙,而是一个C++ 所以我想做的是,如果是一个字符串,检查前4个字符,如果是“http”,做一些事情,如果不是,做一些其他事情 以下是我所拥有的: string strYT= Left(objFile, 4); if (strYT=="http") { pnlYT.Visible = true; pnlIntro.Visible = false; pnlVideo.Visible = fa
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);
}
但我会遇到如下错误:
编译器错误消息:CS0103:类或命名空间“ASP.zen\u aspx”中不存在名称“Left”
我的谷歌搜索找到了许多这样做的例子……这里是VB中的
if (myString.StartsWith("http"))
// do stuff
else
// do other stuff
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
这里是C#
这是用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
这里是C#
在其他答案中,您会注意到它们都使用了
StartsWith(“http”)
。如果只使用StartsWith(“http”)
,那么它也将匹配“https”
。如果要分离安全SSL页面,则需要在其他答案中使用StartsWith(“http://”)
,您会注意到它们都使用StartsWith(“http”)
。如果只使用StartsWith(“http”)
,那么它也将匹配“https”
。如果要分离安全SSL页面,则需要StartsWith(“http://”)
这也将匹配安全的`https`页面。没错。然而,最初的问题并没有要求以不同的方式处理https
。他只想检查前4个字符。我的猜测是,如果他的特定字符串是一个链接,那么他应该做一些其他的事情。如果是这样的话,那么只要http
就可以了。很好的一点是,这也将匹配安全的“https”页面。你是对的。然而,最初的问题并没有要求以不同的方式处理https
。他只想检查前4个字符。我的猜测是,如果他的特定字符串是一个链接,那么他应该做一些其他的事情。如果是这样的话,那么只要http
就可以了。不过说得好
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;
}