string.IndexOf - does not work

  • Thread starter Thread starter Reena
  • Start date Start date
R

Reena

Hi,

code from .aspx page...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

private void Page_Load(object sender, System.EventArgs e)
{
string strServerName =
Request.ServerVariables["SERVER_NAME"].ToUpper();

if (strServerName.IndexOf("LANT") <= 0) //Not Lant
//GETTING ERROR
{
if (strServerName.IndexOf("PAC") <= 0) //Not Pac
{
Response.Write ("<font size=2 face=Arial color=Red>To
access RADWeb site, please use one of the following...");
Response.Write ("<br><br>");
Response.Write ("<A
href='http://pac.com'>https://pac.com</a>");
Response.Write ("<br><br> OR <br><br>");
Response.Write ("<A
href='http://lant.com'>https://lant.com</a>");
Response.Write ("</font>");
Response.End();
}
}
}

-------------------------
Not getting any error while I am running the code. But if I step through the
code, watch window - value field displays 'strServerName.IndexOf' does not
exists.

Even if value is hardcode, strServerName = 'LANT', same error.

Help in this matter is greatly appreciated.

Thanks,

- Reena
 
Reena:

I'm not sure I understand, but I'll give it a crack....Mainly--- you aren't
getting an exception but it just isn't working? What is the value of
strServerName before you test for indexof?
 
there will be no error. the problem is this:
you are saying .indexof <= 0.

if it doesn't exist it will return a -1. if it does exist
it will return anything = to or > 0.

that is the POSITION in the "character array"

HTH.
JS

-----Original Message-----
Hi,

code from .aspx page...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

private void Page_Load(object sender, System.EventArgs e)
{
string strServerName =
Request.ServerVariables["SERVER_NAME"].ToUpper();

if (strServerName.IndexOf("LANT") <= 0) //Not Lant
//GETTING ERROR
{
if (strServerName.IndexOf("PAC") <= 0) //Not Pac
{
Response.Write ("<font size=2 face=Arial color=Red>To
access RADWeb site, please use one of the following...");
Response.Write ("<br><br>");
Response.Write ("<A
href='http://pac.com'>https://pac.com</a>");
Response.Write ("<br><br> OR <br><br>");
Response.Write ("<A
href='http://lant.com'>https://lant.com</a>");
Response.Write ("</font>");
Response.End();
}
}
}
displays 'strServerName.IndexOf' does not
 
Thanks Jerry. Fixed code to .indeof < 0. Works fine.

Thanks,

- Reena

Jerry Sherman said:
there will be no error. the problem is this:
you are saying .indexof <= 0.

if it doesn't exist it will return a -1. if it does exist
it will return anything = to or > 0.

that is the POSITION in the "character array"

HTH.
JS

-----Original Message-----
Hi,

code from .aspx page...

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

private void Page_Load(object sender, System.EventArgs e)
{
string strServerName =
Request.ServerVariables["SERVER_NAME"].ToUpper();

if (strServerName.IndexOf("LANT") <= 0) //Not Lant
//GETTING ERROR
{
if (strServerName.IndexOf("PAC") <= 0) //Not Pac
{
Response.Write ("<font size=2 face=Arial color=Red>To
access RADWeb site, please use one of the following...");
Response.Write ("<br><br>");
Response.Write ("<A
href='http://pac.com'>https://pac.com</a>");
Response.Write ("<br><br> OR <br><br>");
Response.Write ("<A
href='http://lant.com'>https://lant.com</a>");
Response.Write ("</font>");
Response.End();
}
}
}
displays 'strServerName.IndexOf' does not
exists.

Even if value is hardcode, strServerName = 'LANT', same error.

Help in this matter is greatly appreciated.

Thanks,

- Reena




.
 
Back
Top