Please help me to read out each character of a particular line in a rich textbox.
Eg: 6 11 345
I need to read 6 first and then 11 and then 345 etc etc..
Please help me to read out each character of a particular line in a rich textbox.
Eg: 6 11 345
I need to read 6 first and then 11 and then 345 etc etc..
asked how to extract the tokens from a line like 6 11 345. suggested splitting into tokens and showed a positional character access idea. Those approaches work for simple, perfectly formatted input. For input that has varying whitespace, tabs, pasted text with non‑breaking spaces, or stray punctuation, a regular-expression extraction of numeric runs is more reliable.
Sample VB.NET approach that extracts digit runs and parses them safely:
Dim input As String = RichTextBox1.Text ' or the string source
Dim numbers As New List(Of Integer)()
For Each m As Text.RegularExpressions.Match In Text.RegularExpressions.Regex.Matches(input, "\d+")
Dim n As Integer
If Integer.TryParse(m.Value, n) Then
numbers.Add(n)
End If
Next
' numbers now holds 6, 11, 345 in order Notes and variants: use the pattern -?\d+ to allow negative integers, or -?\d+(\.\d+)? for decimals and parse with Decimal.TryParse or Double.TryParse. If the control contains RTF markup, read the plain text (the Text property in WinForms) rather than the RTF stream. Replace non‑breaking spaces before matching, for example input = input.Replace(ChrW(160), " "). For very large inputs precompile the regex or stream the text to avoid high memory usage.
Quick troubleshooting: log each match to confirm ordering; prefer TryParse to avoid exceptions on malformed tokens; pick appropriate numeric type (Integer, Long, Decimal) to avoid overflow. This method preserves the original token order and is robust against variable separators.
Jump to Post— Ranx 0Have you tried using the "Split" method? you can read each line into a string variable and then split it by using the space as the delimiter.
Have you tried using the "Split" method? you can read each line into a string variable and then split it by using the space as the delimiter.
Try with the below code
RichTextBox1.Lines(1).Substring(6, 1) retrieves 6th character in line 1
Does this help you?
Anything more??
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.