Reputation: 47
I have this text in textbox: mytextvariable.mytext
How to extract only text before the dot?
ex: textbox1 = mytext.text
Button Click
textbox2 = mytext without .text
Upvotes: 1
Views: 1970
Reputation: 1503290
Just use simple string manipulation:
string text = textBox1.Text;
int firstDot = text.IndexOf('.');
if (firstDot != -1)
{
string firstPart = text.Susbtring(0, firstDot);
textBox2.Text = firstPart;
}
else
{
// Handle case with no dot
}
Fundamentally, this has nothing to do with the text coming from a textbox - it's just a string, really.
Upvotes: 6
Reputation: 1259
var beforeDot = new String(textBox.Text.TakeWhile(c => c != '.').ToArray());
Upvotes: 2
Reputation: 1277
if (mytextvariable.mytext.Contains("."))
String stuffBeforeTheDot = mytextvariable.mytext.Substring(0, mytextvariable.mytext.IndexOf("."));
Upvotes: 1