Anyone knows how I can read a string value from a textbox (e.g.: 192.168.1.1), split the values using a delimiter, store the values and convert them into int for later use?

Thanks.

string[] parts = textBox1.Text.Split('.');
foreach (string str in parts) {
    int myInt;
    if (Int32.TryParse(str, out myInt)) {
        // Do something with the value in myInt
    } else {
        // the string wasn't an integer, can do something if I want
    }
}

You should be able to do

string[] octets = ipTextBox.Text.Split('.');
int octet1 = Convert.ToInt32(octets[0]);
int octet2 = Convert.ToInt32(octets[1]);
//... etc.

But if you're specifically using an IP address, I'm sure there's a constructor for an IP address object of some sort that takes a string in dotted-decimal notation for an IP address IPAddress myIP = new IPAddress(ipTextBox.Text);

Alrights thanks all. My problem has been solved.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.