Search code examples
c#regextextsplittextbox

Visual C# 2010 - Comma separate contents of Text Box


I'm trying to create an application where the end user can copy and paste a number of email addresses into a text box, these email addresses will then all be moved onto one line and separated with a comma and a space, apart from the last one, the resulting value will then be assigned to a variable.

How can I split up and comma separate the text value of the textbox as required?


Solution

  • I'll need to assume that these email addresses will be like:

    "email1; email2; email3; emailN"

    You can use String.Split method:

    string[] emailAddresses = txtBox.Text.Split(";");
    

    Is this what you're looking for?