Results 1 to 9 of 9

Thread: again , VB.NET equivalent??[Resolved]

  1. #1

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083

    again , VB.NET equivalent??[Resolved]

    What's the equivalent of InStr that accepts (string, string) and return an integer specifying the start position of the first occurrence of one string within another. I had a look at Compare methods but it didn't help much .


    VB Code:
    1. Dim lNullPos As Integer
    2. Dim sBuffer As String
    3.  
    4. lNullPos = InStr(sBuffer, vbNullChar)
    Last edited by Pirate; Jul 26th, 2003 at 07:06 PM.

  2. #2
    Hyperactive Member
    Join Date
    Feb 2002
    Posts
    261
    Do you code in Visual Studio? The intellisense would list all of the available functions in the String class.

    Dim strMyString as String = "Whatever"
    Dim intIndex as Integer = strMyString.IndexOf("ate")

  3. #3

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Not sure if that would solve it but I need something like the code I posted . I mean boths string variables will not be fixed , they're always change . So .....

  4. #4
    Frenzied Member dynamic_sysop's Avatar
    Join Date
    Jun 2003
    Location
    Ashby, Leicestershire.
    Posts
    1,142
    VB Code:
    1. Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
    2.         Dim x As String = "hello : ) How are you"
    3.  
    4.         MessageBox.Show(x.IndexOf("How"))
    5.  
    6.         'Or
    7.         MessageBox.Show(InStr(x, "How") - 1)
    8.  
    9.     End Sub
    ~
    if a post is resolved, please mark it as [Resolved]
    protected string get_Signature(){return Censored;}
    [vbcode][php] please use code tags when posting any code [/php][/vbcode]

  5. #5
    Hyperactive Member
    Join Date
    Mar 2002
    Location
    Dublin (Ireland)
    Posts
    304
    Dim mytext As String = "abc"
    Dim mypos As integer = InStr(mytext, "c", CompareMethod.Text)

    In this case mypos will be set to 3. You can also use a compare method of binary.

    was that what you were looking for?

  6. #6

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    I want to replace InStr function which for VB6 Code imported from VisualBasic namespace with pure .NET way . That's what I'm looking for .

  7. #7

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    btw , keep in mind that both strings are changeable . So the code dynamic_sysop and RichardAtherton are not applicable .

    Thanks guys .

  8. #8

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Never mind , figured it out

    VB Code:
    1. lNullPos = sBuffer.IndexOf(Nothing) + 1

  9. #9

    Thread Starter
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Thanks both of you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width