how can i get the first value in a text box and place it to a label. Example, I want to get the word "look" in the textbox that I input was "look like".

有帮助吗?

解决方案

You could use substring, this will split the string or aka your textbox.

This takes two params, The starting index of the string and the 2nd param is the length. I have put str.indexof in the 2nd param to get the index of where the space is.

dim str as string
Label1.Text = str.Substring(0, str.IndexOf(" "))

This code is not tested, I only used visual basic for a little bit when i was 12.

其他提示

you can simply split the value by " " space and take the first one from result array

if(!String.IsNullOrEmpty(textBox1.Text))
{
lable1.Text = textBox1.Text.Split(" ").first();
}
textboxValue = Textbox.Text;
str = textboxValue.Split(" ").first();
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top