Searching text in ASP.net

Discussion in 'ASP .Net' started by jty202, Jan 17, 2005.

  1. jty202

    jty202 Guest

    I use a the function Instr() in VB6 to search for a search-string in String
    var. It returns the position of the found search-string.

    Is there such a funtion in ASP.net?
     
    jty202, Jan 17, 2005
    #1
    1. Advertising

  2. Hi,

    You could try this:

    Dim findIt as String = "The String"
    Dim startPosition as Integer
    Dim position as integer = findIt.IndexOf("String you are looking in",
    startPosition)

    Hope this helps.

    Stuart
    MCSD, MCT

    More Examples from MSDN:

    [Visual Basic]
    ' Sample for String.IndexOf(Char, Int32)
    Imports System

    Class Sample
    Public Shared Sub Main()

    Dim br1 As String =
    "0----+----1----+----2----+----3----+----4----+----5----+----6----+-"
    Dim br2 As String =
    "0123456789012345678901234567890123456789012345678901234567890123456"
    Dim str As String = "Now is the time for all good men to come to the
    aid of their party."
    Dim start As Integer
    Dim at As Integer

    Console.WriteLine()
    Console.WriteLine("All occurrences of 't' from position 0 to {0}.",
    str.Length - 1)
    Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2,
    str)
    Console.Write("The letter 't' occurs at position(s): ")

    at = 0
    start = 0
    While start < str.Length AndAlso at > - 1
    at = str.IndexOf("t"c, start)
    If at = - 1 Then
    Exit While
    End If
    Console.Write("{0} ", at)
    start = at + 1
    End While
    Console.WriteLine()
    End Sub 'Main
    End Class 'Sample
    '
    'This example produces the following results:
    '
    'All occurrences of 't' from position 0 to 66.
    '0----+----1----+----2----+----3----+----4----+----5----+----6----+-
    '0123456789012345678901234567890123456789012345678901234567890123456
    'Now is the time for all good men to come to the aid of their party.
    '
    'The letter 't' occurs at position(s): 7 11 33 41 44 55 64
    '
    '

    [C#]
    // Sample for String.IndexOf(Char, Int32)
    using System;

    class Sample {
    public static void Main() {

    string br1 =
    "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
    string br2 =
    "0123456789012345678901234567890123456789012345678901234567890123456";
    string str = "Now is the time for all good men to come to the aid of
    their party.";
    int start;
    int at;

    Console.WriteLine();
    Console.WriteLine("All occurrences of 't' from position 0 to {0}.",
    str.Length-1);
    Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2,
    str);
    Console.Write("The letter 't' occurs at position(s): ");

    at = 0;
    start = 0;
    while((start < str.Length) && (at > -1))
    {
    at = str.IndexOf('t', start);
    if (at == -1) break;
    Console.Write("{0} ", at);
    start = at+1;
    }
    Console.WriteLine();
    }
    }
    /*
    This example produces the following results:

    All occurrences of 't' from position 0 to 66.
    0----+----1----+----2----+----3----+----4----+----5----+----6----+-
    0123456789012345678901234567890123456789012345678901234567890123456
    Now is the time for all good men to come to the aid of their party.

    The letter 't' occurs at position(s): 7 11 33 41 44 55 64


    "jty202" <> wrote in message
    news:e%232sNsN$...
    >I use a the function Instr() in VB6 to search for a search-string in String
    > var. It returns the position of the found search-string.
    >
    > Is there such a funtion in ASP.net?
    >
    >
     
    Stuart A Hill, Jan 17, 2005
    #2
    1. Advertising

  3. jty202

    Matt Berther Guest

    Hello jty202,

    string s = "Foo";
    int pos = s.IndexOf("o");

    Its a function of the string object which is part of the .NET framework,
    not just ASP.NET.

    --
    Matt Berther
    http://www.mattberther.com

    > I use a the function Instr() in VB6 to search for a search-string in
    > String var. It returns the position of the found search-string.
    >
    > Is there such a funtion in ASP.net?
    >
     
    Matt Berther, Jan 17, 2005
    #3
  4. jty202

    Cor Ligthert Guest

    Cor Ligthert, Jan 18, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David

    Asp.net Website - Searching

    David, Jan 27, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    332
    Chad Crowder
    Jan 27, 2004
  2. Matthias Mohr via .NET 247

    Searching the domain with WinNT Provider in ASP.NET

    Matthias Mohr via .NET 247, Jul 3, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    564
    Natty Gur
    Jul 4, 2004
  3. Guest

    Searching a gridview ASP.NET 2.0

    Guest, Dec 15, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    3,651
    Steven Cheng[MSFT]
    Dec 16, 2005
  4. Brian Henry

    text searching a dynamic ASP.NET site?

    Brian Henry, Mar 27, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    354
  5. stumblng.tumblr
    Replies:
    1
    Views:
    233
    stumblng.tumblr
    Feb 4, 2008
Loading...

Share This Page