Вопрос

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