string.IndexOf - does not work

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Reena

    #1

    string.IndexOf - does not work

    Hi,

    code from .aspx page...

    using System;
    using System.Collecti ons;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.Sess ionState;
    using System.Web.UI;
    using System.Web.UI.W ebControls;
    using System.Web.UI.H tmlControls;

    private void Page_Load(objec t sender, System.EventArg s e)
    {
    string strServerName =
    Request.ServerV ariables["SERVER_NAM E"].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




  • Ignacio Machin

    #2
    Re: string.IndexOf - does not work

    Hi Reena,

    It runs fine onmy computer, what error does it give you?

    cheers,

    --
    Ignacio Machin,
    ignacio.machin AT dot.state.fl.us
    Florida Department Of Transportation


    Comment

    • William Ryan

      #3
      Re: string.IndexOf - does not work

      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?
      "Reena" <palejar@navsea .navy.mil> wrote in message
      news:e2WSWxidDH A.2168@TK2MSFTN GP09.phx.gbl...[color=blue]
      > Hi,
      >
      > code from .aspx page...
      >
      > using System;
      > using System.Collecti ons;
      > using System.Componen tModel;
      > using System.Data;
      > using System.Drawing;
      > using System.Web;
      > using System.Web.Sess ionState;
      > using System.Web.UI;
      > using System.Web.UI.W ebControls;
      > using System.Web.UI.H tmlControls;
      >
      > private void Page_Load(objec t sender, System.EventArg s e)
      > {
      > string strServerName =
      > Request.ServerV ariables["SERVER_NAM E"].ToUpper();
      >
      > if (strServerName. IndexOf("LANT") <= 0) //Not[/color]
      Lant[color=blue]
      > //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[/color]
      the[color=blue]
      > 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
      >
      >
      >
      >[/color]


      Comment

      • Jerry Sherman

        #4
        string.IndexOf - does not work

        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

        [color=blue]
        >-----Original Message-----
        >Hi,
        >
        >code from .aspx page...
        >
        >using System;
        >using System.Collecti ons;
        >using System.Componen tModel;
        >using System.Data;
        >using System.Drawing;
        >using System.Web;
        >using System.Web.Sess ionState;
        >using System.Web.UI;
        >using System.Web.UI.W ebControls;
        >using System.Web.UI.H tmlControls;
        >
        >private void Page_Load(objec t sender, System.EventArg s e)
        > {
        > string strServerName =
        >Request.Server Variables["SERVER_NAM E"].ToUpper();
        >
        > if (strServerName. IndexOf("LANT") <=[/color]
        0) //Not Lant[color=blue]
        >//GETTING ERROR
        > {
        > if (strServerName. IndexOf("PAC") <=[/color]
        0) //Not Pac[color=blue]
        > {
        > Response.Write ("<font size=2 face=Arial[/color]
        color=Red>To[color=blue]
        >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[/color]
        I step through the[color=blue]
        >code, watch window - value field[/color]
        displays 'strServerName. IndexOf' does not[color=blue]
        >exists.
        >
        >Even if value is hardcode, strServerName = 'LANT', same[/color]
        error.[color=blue]
        >
        >Help in this matter is greatly appreciated.
        >
        >Thanks,
        >
        >- Reena
        >
        >
        >
        >
        >.
        >[/color]

        Comment

        • Reena

          #5
          Re: string.IndexOf - does not work

          Thanks Jerry. Fixed code to .indeof < 0. Works fine.

          Thanks,

          - Reena

          "Jerry Sherman" <JS@nospam.co m> wrote in message
          news:3caf01c376 30$58116a70$a30 1280a@phx.gbl.. .[color=blue]
          > 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
          >
          >[color=green]
          > >-----Original Message-----
          > >Hi,
          > >
          > >code from .aspx page...
          > >
          > >using System;
          > >using System.Collecti ons;
          > >using System.Componen tModel;
          > >using System.Data;
          > >using System.Drawing;
          > >using System.Web;
          > >using System.Web.Sess ionState;
          > >using System.Web.UI;
          > >using System.Web.UI.W ebControls;
          > >using System.Web.UI.H tmlControls;
          > >
          > >private void Page_Load(objec t sender, System.EventArg s e)
          > > {
          > > string strServerName =
          > >Request.Server Variables["SERVER_NAM E"].ToUpper();
          > >
          > > if (strServerName. IndexOf("LANT") <=[/color]
          > 0) //Not Lant[color=green]
          > >//GETTING ERROR
          > > {
          > > if (strServerName. IndexOf("PAC") <=[/color]
          > 0) //Not Pac[color=green]
          > > {
          > > Response.Write ("<font size=2 face=Arial[/color]
          > color=Red>To[color=green]
          > >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[/color]
          > I step through the[color=green]
          > >code, watch window - value field[/color]
          > displays 'strServerName. IndexOf' does not[color=green]
          > >exists.
          > >
          > >Even if value is hardcode, strServerName = 'LANT', same[/color]
          > error.[color=green]
          > >
          > >Help in this matter is greatly appreciated.
          > >
          > >Thanks,
          > >
          > >- Reena
          > >
          > >
          > >
          > >
          > >.
          > >[/color][/color]


          Comment

          Working...