Results 1 to 12 of 12

Thread: Richtextbox instance of string search

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Richtextbox instance of string search

    I want to get a string from the richtextbox but here how it goes

    in programming for example i want to get all class/function and variable names in this given code.


    Private Function Processstring(ByVal strin As String) As String
    Dim astrWords As String() = New String() {"parrot"}
    Dim strOut As String = strin
    Dim strWord As String
    For Each strWord In astrWords
    If strin.indexOf(strWord, 0) >= 0 Then
    strOut = strWord
    Exit For
    End If
    Next
    Return strOut
    End Function
    how would i get the "processstring" by getting it after the word function?

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Richtextbox instance of string search

    i don't understand the question

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Re: Richtextbox instance of string search

    Quote Originally Posted by .paul. View Post
    i don't understand the question
    I'm creating a texteditor and i want to copy all the function names that will be added in the richtextbox.

    how would i search for all the function names in the richtextbox if their would be many functions in it?

  4. #4
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Richtextbox instance of string search

    you could use regex:

    vb Code:
    1. Dim rx As New Regex("(?<=(Function|Sub)\s).+?(?=\()")
    2.  
    3. For Each m As Match In rx.Matches(RichTextBox1.Text)
    4.     MsgBox(m.Value)
    5. Next

    don't forget to import regex:

    vb Code:
    1. Imports System.Text.RegularExpressions

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Re: Richtextbox instance of string search

    I've added the code in a button but no msgbox that appears.

  6. #6
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Richtextbox instance of string search

    can you post an example of RichTextBox1.Text?

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Re: Richtextbox instance of string search

    Private Function Processstring(ByVal strin As String) As String
    Dim astrWords As String() = New String() {"parrot"}
    Dim strOut As String = strin
    Dim strWord As String
    For Each strWord In astrWords
    If strin.indexOf(strWord, 0) >= 0 Then
    strOut = strWord
    Exit For
    End If
    Next
    Return strOut
    End Function
    just like that.. from that i will be expecting the function name: Processstring

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Re: Richtextbox instance of string search

    i retried it and it work.. thanks for all.. another one is how about getting variablenames after the dim?

  9. #9
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Richtextbox instance of string search

    different regex:

    vb Code:
    1. Dim rx As New Regex("(?<=Dim\s).+?(?=\b)")

    it'll return local variables + arrays

  10. #10

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Re: Richtextbox instance of string search

    wow! thanks.. do you have any software making the regular expressions?

    I'd like also to create regex for c++ variables and functions..

  11. #11
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: Richtextbox instance of string search


  12. #12

    Thread Starter
    Lively Member
    Join Date
    Sep 2009
    Posts
    67

    Re: Richtextbox instance of string search

    gee thanks lot bro.

Tags for this Thread

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