VB.NET RichTextBox和TextBox分离

时间:2014-07-17 19:08:21

标签: vb.net richtextbox

对于我的公司,我们会收到以下格式的时间表

Name:Hours
Name:Hours
Name:Hours

我将Timesheet.txt加载到RichTextBox1中,但是,当我点击一个按钮将它们加载到两个不同的文本框中时,我想要。我希望将Names加载到TextBox1中,将小时加载到TextBox2

然后删除该行。当我再次点击按钮时,它将进入下一行。

任何帮助?

2 个答案:

答案 0 :(得分:1)

简单,但会做:

Dim sInput As String = "Name:10"
Dim sSplitArray() As String = sInput.Split(New Char() {":"c})
Dim sName As String = sSplitArray(0)
Dim sHours As String = sSplitArray(1)

String的Split函数按照传递给它的字符将字符串拆分。

所以如果你有这个:

sInput = "Name:10:Zebra:Kazaam"

当您通过“:”分隔符拆分该字符串时,它将为您提供一个包含以下内容的数组:

Name
10
Zebra
Kazaam

答案 1 :(得分:0)

希望这能为您的问题提供完整的解决方案

Dim x, y As Integer
Dim textbox1() As TextBox
x = 430
y = 265
Dim str As String
Dim result(), output(1) As String'str=RitchText1.text 'load input string to str
result = str.Split(System.Environment.NewLine) ' split into array based on new line
For i As Integer = 0 To result.Length - 1 'execute up to array limit
output = result(i).Split(":") 'split again based on :
textbox1(i).Text = output(0) 'Name part into dynamic textbox 1
textbox1(i).Location = New Point(x, y)
textbox1(i + 1).Text = output(1) 'Name part into dynamic textbox 2
textbox1(i + 1).Location = New Point(x + 40, y)
Me.Controls.Add(textbox1(i))
textbox1(i).Visible = True
Me.Controls.Add(textbox1(i + 1))
textbox1(i + 1).Visible = True
y = y + 20
Next