Click to See Complete Forum and Search --> : Problem with IndexOf in a aspx page


SandyR
May 29th, 2003, 02:32 PM
Hi,

I use VB.NET and ASP.NET.

I'm trying to use IndexOf for search a substring. I use this function a lot but never functions to me.

I want the index of the begin and end of a substring but always return 0 even is the substring exist.

My strSource have several CR-LF inside.

What I'm doing wrong?

Thanks in advance, Sandy

PS:
The code follows:

Private Function FindSubstring(ByVal strSource As String) As String
Dim intBegin As Integer = 0
Dim intEnd As Integer = 0

If intBegin = strSource .IndexOf("StringSearched: ") <= 0 Then
Return 0
End If

' I want to consider the position after the :
intBegin = strSource .IndexOf(" ", intBegin)

' Find the position of carriage return-line feed
If intEnd = strSource .Substring(intBegin ).IndexOf(vbCrLf) <= 0 Then
Return 0
End If

Return strSource.Substring(intBegin, intEnd - intBegin - 1)

End Function

SandyR
June 1st, 2003, 12:44 PM
Hi,

I found a solution by myself. I put this here because maybe could be useful for someone of you.

I change

If intBegin = strSource .IndexOf("StringSearched: ") <= 0 Then

with

intBegin = strSource .IndexOf("StringSearched: ")
If intBegin <= 0 Then

and works.

Bye, Sandy