vb.net 如何拆分文本框值然后在标签上显示拆分值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21592662/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-17 16:41:24  来源:igfitidea点击:

How to split textbox value then display splitted value on label

vb.netvisual-studio-2010.net-4.0

提问by elcabronel

How to split a text box (delimited by "-") value then display the split values on two labels?

如何拆分文本框(以“-”分隔)值然后在两个标签上显示拆分值?

Heres my code:

这是我的代码:

    Dim s As String
    Dim substring As String
    Dim sp() As String

    s = txtTime1.Text 'this text box contains value (08:00-17:41)
    sp = s.Split("-")

    For Each substring In sp
        txtTimeIn.Text = substring
        txtTimeOut.Text = substring
    Next

My problem is txtTimeIn and txtTimeOut displays only value '17:41'. Thank you so much in advance.

我的问题是 txtTimeIn 和 txtTimeOut 只显示值“17:41”。非常感谢你提前。

采纳答案by Thejaka Maldeniya

Try this:

尝试这个:

Dim s As String
Dim substring As String
Dim sp() As String

s = txtTime1.Text 'this text box contains value (08:00-17:41)
sp = s.Split("-")

txtTimeIn.Text = sp(0)
txtTimeOut.Text = sp(1)