|
-
Apr 10th, 2013, 07:30 AM
#1
Thread Starter
Lively Member
RichTextBox Multiline to RichTextBox Singleline
Hi all , I have a small problem, I'm loading a file to RichTextBox1:
Number: 1' Location: DVD' NrLocation: 1' Name: Movie 1' Year: 2013' Number: 2' Location: DVD' NrLocation: 2' Name: Movie 2' Year: 2013' Number: 3' Location: DVD' NrLocation: 3' Name: Movie 3' Year: 2013' Number: 4' Location: DVD' NrLocation: 4' Name: Movie 4' Year: 2013' Number: 5' Location: DVD' NrLocation: 5' Name: Movie 5' Year: 2013' Number: 6' Location: DVD' NrLocation: 6' Name: Movie 6' Year: 2013' Number: 7' Location: DVD' NrLocation: 7' Name: Movie 7' Year: 2013' Number: 8' Location: DVD' NrLocation: 8' Name: Movie 8' Year: 2013' Number: 9' Location: DVD' NrLocation: 9' Name: Movie 9' Year: 2013' Number: 10' Location: DVD' NrLocation: 10' Name: Movie 10' Year: 2013' Number: 11' Location: DVD' NrLocation: 11' Name: Movie 11' Year: 2013' Number: 12' Location: DVD' NrLocation: 12' Name: Movie 12'
I want to copy all numbers to RichTextBox2 and all names to RichTextBox3, so, my RichTextBox2 should look like this:
and my RichTextBox3 should look like this:
Code:
Movie 1
Movie 2
Movie 3
...
so far I got only the first number and the first name, but I need all of the numbers and all names.
-
Apr 10th, 2013, 02:55 PM
#2
Re: RichTextBox Multiline to RichTextBox Singleline
Ah yes, Movie 2, always loved that one!
Split on '[space] and loop through the resulting array checking for Number or Name would appear to be the obvious solution.
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 10th, 2013, 05:56 PM
#3
Thread Starter
Lively Member
Re: RichTextBox Multiline to RichTextBox Singleline
 Originally Posted by dunfiddlin
Ah yes, Movie 2, always loved that one!
Split on '[space] and loop through the resulting array checking for Number or Name would appear to be the obvious solution.
Do you have any examples? 
I even found this but still nothing:
Code:
Dim lines() As String = RichTextBox1.Lines
RichTextBox2.Text = Array.Find(lines, Function(s) s.StartsWith("Number: ")).Split(New String() {":"}, StringSplitOptions.None)(1).TrimEnd("'"c)
RichTextBox3.Text = Array.Find(lines, Function(s) s.StartsWith("Name: ")).Split(New String() {":"}, StringSplitOptions.None)(1).TrimEnd("'"c)
-
Apr 10th, 2013, 07:46 PM
#4
Re: RichTextBox Multiline to RichTextBox Singleline
vb.net Code:
Dim s As String = "Number: 1' Location: DVD' NrLocation: 1' Name: Movie 1' Year: 2013' Number: 2' Location: DVD' NrLocation: 2' Name: Movie 2' Year: 2013' Number: 3' Location: DVD' NrLocation: 3' Name: Movie 3' Year: 2013' Number: 4' Location: DVD' NrLocation: 4' Name: Movie 4' Year: 2013' Number: 5' Location: DVD' NrLocation: 5' Name: Movie 5' Year: 2013' Number: 6' Location: DVD' NrLocation: 6' Name: Movie 6' Year: 2013' Number: 7' Location: DVD' NrLocation: 7' Name: Movie 7' Year: 2013' Number: 8' Location: DVD' NrLocation: 8' Name: Movie 8' Year: 2013' Number: 9' Location: DVD' NrLocation: 9' Name: Movie 9' Year: 2013' Number: 10' Location: DVD' NrLocation: 10' Name: Movie 10' Year: 2013' Number: 11' Location: DVD' NrLocation: 11' Name: Movie 11' Year: 2013' Number: 12' Location: DVD' NrLocation: 12' Name: Movie 12'" Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Dim splits = s.Split({"' "}, StringSplitOptions.RemoveEmptyEntries) For Each st In splits If st.StartsWith("Number:") Then RichTextBox2.AppendText(st.Split(" "c)(1) & vbCrLf) ElseIf st.StartsWith("Name:") Then RichTextBox3.AppendText(st.Split({": "}, StringSplitOptions.None)(1) & vbCrLf) End If Next End Sub
As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"
Reviews: "dunfiddlin likes his DataTables" - jmcilhinney
Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!
-
Apr 11th, 2013, 12:42 PM
#5
Re: RichTextBox Multiline to RichTextBox Singleline
Another way using regular expressions.
vb Code:
Imports System.Text.RegularExpressions Public Class MainForm Private ReadOnly m_source As String = "Number: 1' Location: DVD' NrLocation: 1' Name: Movie 1' Year: 2013'" & _ "Number: 2' Location: DVD' NrLocation: 2' Name: Movie 2' Year: 2013'" & _ "Number: 3' Location: DVD' NrLocation: 3' Name: Movie 3' Year: 2013' " & _ "Number: 4' Location: DVD' NrLocation: 4' Name: Movie 4' Year: 2013' " & _ "Number: 5' Location: DVD' NrLocation: 5' Name: Movie 5' Year: 2013' " & _ "Number: 6' Location: DVD' NrLocation: 6' Name: Movie 6' Year: 2013' " & _ "Number: 7' Location: DVD' NrLocation: 7' Name: Movie 7' Year: 2013' " & _ "Number: 8' Location: DVD' NrLocation: 8' Name: Movie 8' Year: 2013' " & _ "Number: 9' Location: DVD' NrLocation: 9' Name: Movie 9' Year: 2013' " & _ "Number: 10' Location: DVD' NrLocation: 10' Name: Movie 10' Year: 2013' " & _ "Number: 11' Location: DVD' NrLocation: 11' Name: Movie 11' Year: 2013' " & _ "Number: 12' Location: DVD' NrLocation: 12' Name: Movie 12' Year: 2013'" Private ReadOnly m_pattern As String = "Number\: (?<Number>.+?)\' Location\: DVD\' " & _ "NrLocation: \d{1,}' Name\: (?<Name>.+?)\' Year\: \d{4}\'" Private ReadOnly m_match As New Regex(m_pattern, RegexOptions.IgnoreCase Or RegexOptions.Compiled) Private Sub MainForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim matches = Me.m_match.Matches(Me.m_source) For Each m As Match In matches Me.RichTextBox1.AppendText(m.Groups("Number").Value & Environment.NewLine) Me.RichTextBox2.AppendText(m.Groups("Name").Value & Environment.NewLine) Next End Sub End Class
-
Apr 11th, 2013, 02:37 PM
#6
Thread Starter
Lively Member
Re: RichTextBox Multiline to RichTextBox Singleline
Thanks guys, you are the best. Best forum ever.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|