Results 1 to 5 of 5

Thread: [RESOLVED] How to get x number of characters after a string?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Resolved [RESOLVED] How to get x number of characters after a string?

    Say I open a text file in a richtextbox control. After that I search for a specific string like "6.1". The string actually continues like "6.1XXXXXXX". I need to get not just only "6.1", but also 2 more chars after "6.1", like "6.1XX". i will then output this in a textbox, but i can do that, I don't know how to get the X number of characters, any help or idea with that?

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

    Re: How to get x number of characters after a string?

    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim findString As String = "6.1"
    3.     TextBox1.Text = RichTextBox1.Text.Substring(RichTextBox1.Text.IndexOf(findString), findString.Length + 2)
    4. End Sub

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Smile Re: How to get x number of characters after a string?

    Quote Originally Posted by .paul. View Post
    try this:

    vb Code:
    1. Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    2.     Dim findString As String = "6.1"
    3.     TextBox1.Text = RichTextBox1.Text.Substring(RichTextBox1.Text.IndexOf(findString), findString.Length + 2)
    4. End Sub
    THANK YOU sooooo much, you have helped me a lot with this one, you can call this thread resolved now! Once again, thanks!

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to get x number of characters after a string?

    Quote Originally Posted by Legjendat View Post
    you can call this thread resolved now!
    Or you can, using the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Apr 2010
    Posts
    131

    Re: How to get x number of characters after a string?

    Quote Originally Posted by jmcilhinney View Post
    Or you can, using the Thread Tools menu.
    My bad, sorry, never had a thread resolved till now, this was the first one so I didn't know I could call it resolved myself, done now!

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