Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Searching text in ASP.net

Reply
Thread Tools

Searching text in ASP.net

 
 
jty202
Guest
Posts: n/a
 
      01-17-2005
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?


 
Reply With Quote
 
 
 
 
Stuart A Hill
Guest
Posts: n/a
 
      01-17-2005
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 =
"0123456789012345678901234567890123456789012345678 901234567890123456"
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----+-
'0123456789012345678901234567890123456789012345678 901234567890123456
'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 =
"0123456789012345678901234567890123456789012345678 901234567890123456";
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----+-
01234567890123456789012345678901234567890123456789 01234567890123456
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" <(E-Mail Removed)> wrote in message
news:e%232sNsN$(E-Mail Removed)...
>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?
>
>



 
Reply With Quote
 
 
 
 
Matt Berther
Guest
Posts: n/a
 
      01-17-2005
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?
>



 
Reply With Quote
 
Cor Ligthert
Guest
Posts: n/a
 
      01-18-2005
jty,

As far as I know is the Instr in VB6 the same as in VBNet
(You can use it as well in C# when you set a reference to the
Microsoft.VisualBasic namespace)

http://msdn.microsoft.com/library/de...vafctinstr.asp

I hope this helps?

Cor


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Google search result to be URL-limited when searching site, but notwhen searching Web stumblng.tumblr Javascript 1 02-04-2008 09:01 AM
text searching a dynamic ASP.NET site? Brian Henry ASP .Net 3 04-15-2006 02:34 AM
Searching text in Excel, Word files Rene Aguirre Python 0 03-03-2004 04:24 PM
Searching and replacing multiple strings in text Chris Java 5 10-11-2003 05:12 AM
Searching text files hivie C++ 3 07-08-2003 03:42 PM



Advertisments