insert string
If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
5 posts
Page 1 of 1
i have a richtextbox with the following lines
i need a way to insert this text "stop" after the last "test" line
is this possible?
Code: Select all
and so ontest 1
test 2
test 3
hello 1
hello 2
hello 3
i need a way to insert this text "stop" after the last "test" line
is this possible?
Last edited by XTechVB on Sat May 12, 2012 5:54 pm, edited 1 time in total.
You can find me on Facebook or on Skype mihai_92b
If you're talking about inserting the word "stop" on a new line after the text you have here, you could try this:
Code: Select all
If not, I'm not sure what you were asking for :lol:RichTextBox1.Text=RichTextBox1.Text & vbNewLine & "stop"
Code: Select all
I think that will work, but only with tests up to "test 9". If you need more, like "test 99" you need to replace "\d" with "\d{2}", or for "test 999" you would replace with "\d{3}".Imports System.Text.RegularExpressions
'
'
Dim Matches As MatchCollection = Regex.Matches(RichTextBox1.Text, "test \d", RegexOptions.Multiline Or RegexOptions.IgnoreCase)
Dim Index As Integer = Matches(Matches.Length - 1).Index + Matches(Matches.Length - 1).Length
RichTextBox1.Text = RichTextBox1.Text.Insert(Index, vbNewLine + "Stop")
Last edited by MrAksel on Sun May 13, 2012 10:31 am, edited 1 time in total.
LMAOSHMSFOAIDMT
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!
![Image]()
![Image]()
Laughing my a** of so hard my sombrero fell off and I dropped my taco lmao;
Over 30 projects with source code!
Please give reputation to helpful members!

If you don't want to hard code it so much you can use this:
Code: Select all
Dim starting As Integer = RichTextBox1.Text.LastIndexOf(vbLf & "test ")
Dim index As Integer = RichTextBox1.Text.IndexOf(vbLf, starting + 1)
If index > -1 Then
RichTextBox1.Text = RichTextBox1.Text.Insert(index, " stop")
End If
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023