| |

VerySource

 Forgot password?
 Register
Search
Author: emptyname

How to go to a certain line in richtextbox

[Copy link]

0

Threads

14

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-11 21:45:01
| Show all posts
If your carriage returns are all hard carriage returns, consider using regular expression objects to simplify operations.

The purpose of my program is to delete blank lines and blank lines containing spaces:
Private Sub Command1_Click()
Dim temp As String, s() As String, i As Long
temp = RichTextBox1.Text
s = Split(temp, vbCrLf)
For i = 0 To UBound(s)
If Len(Trim(s(i))) = 0 Then s(i) = ""
Next
temp = Join(s, vbCrLf)
While InStr(temp, vbCrLf&vbCrLf)> 0
temp = Replace(temp, vbCrLf&vbCrLf, vbCrLf)
Wend
RichTextBox1.Text = temp
End Sub
Reply

Use magic Report

1

Threads

7

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2021-3-11 22:00:01
| Show all posts
talent00168Hello, will the above code delete the text format in richtextbox? It seems to delete the text format in richtextbox
Reply

Use magic Report

0

Threads

14

Posts

6.00

Credits

Newbie

Rank: 1

Credits
6.00

 China

Post time: 2021-3-11 22:15:01
| Show all posts
If they are all hard returns, you can locate them like this:
Private Sub Command1_Click()
Randomize
Dim n As Long, s() As String
n = CLng(InputBox("How many lines the cursor points to", "info", Int(Rnd * 100)))-1
s = Split(RichTextBox1.Text, vbCrLf)
ReDim Preserve s(n-1)
n = Len(Join(s, vbCrLf)) + Len(vbCrLf)
RichTextBox1.SetFocus
RichTextBox1.SelStart = n
End Sub
Reply

Use magic Report

1

Threads

7

Posts

2.00

Credits

Newbie

Rank: 1

Credits
2.00

 China

 Author| Post time: 2021-3-11 22:30:01
| Show all posts
talent00168hello, thank you for being able to locate it, thank you so much, masters are different
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list