Home > Mobile >  How to extract part of a selected richtextbox line and copy it into a textbox
How to extract part of a selected richtextbox line and copy it into a textbox

Time:02-23

I have this output in a richtextbox

0.00001148 - 324.8K
0.00001137 - 452.4K
0.00001125 - 1.4M
0.00001114 - 436.9K
0.00001103 - 111.6K
0.00001092 - 351.8K
0.00001081 - 433.1K
0.00001071 - 320.9K
0.0000106 - 344K
0.0000104 - 9.9K

and through the Mouse Click event of the richtextbox I'm using

Dim firstcharindex As Integer = RichTextBox1.GetFirstCharIndexOfCurrentLine()
Dim currentline As Integer = RichTextBox1.GetLineFromCharIndex(firstcharindex)
Dim currentlinetext As String = RichTextBox1.Lines(currentline)
RichTextBox1.Select(firstcharindex, currentlinetext.Length) 

to select a single line of the RichTextBox.

I want now to extract the first number ( double or decimal ) of the selected line and copy it into a textbox. E.g. Selecting the line 0.00001148 - 324.8K would send to a textbox the value 0.00001148.

Thanks

CodePudding user response:

Dim currentlinechosen As String = Mid(currentlinetext, 1, InStr(currentlinetext, " -") - 1)
    MsgBox(currentlinechosen)

Just assign the currentlinechoosen to a textbox

CodePudding user response:

You could take the selected line and convert it to a string of text:

dim sel_line as string = currentline.ToString()

then extract the first part of the line by splitting it on the "-":

dim temp_string as String() = sel_line.split("-")

and then the first index of temp_string will contain your number

textbox.text = temp_string(0)
  • Related