Combining Array with delimiters
-
I want to use array to retrieve all the emails from my contacts for example. and i want to use delimiters to seperate all the emails with a semicolon ; and then i need to join them back as a string again to put it in a textbox. How do I do that? :confused: Urgent help is needed. Thank you
-
I want to use array to retrieve all the emails from my contacts for example. and i want to use delimiters to seperate all the emails with a semicolon ; and then i need to join them back as a string again to put it in a textbox. How do I do that? :confused: Urgent help is needed. Thank you
Create the array:
//edited, as retrieving the string may not be apparent:
string emailString = NameOfTextBox.Text;
string[] emailArr = emailString.Split(';');Recreate the string:
//remember "using System.Text"
StringBuilder sb = new StringBuilder();foreach (string s in emailArr)
sb.AppendFormat("{0};", s);string rebuiltString = sb.ToString();
-
Create the array:
//edited, as retrieving the string may not be apparent:
string emailString = NameOfTextBox.Text;
string[] emailArr = emailString.Split(';');Recreate the string:
//remember "using System.Text"
StringBuilder sb = new StringBuilder();foreach (string s in emailArr)
sb.AppendFormat("{0};", s);string rebuiltString = sb.ToString();
-
Create the array:
//edited, as retrieving the string may not be apparent:
string emailString = NameOfTextBox.Text;
string[] emailArr = emailString.Split(';');Recreate the string:
//remember "using System.Text"
StringBuilder sb = new StringBuilder();foreach (string s in emailArr)
sb.AppendFormat("{0};", s);string rebuiltString = sb.ToString();
but I am retrieving the numbers of emails using SQL statement which will be called using the button. which is then I need an array and delimiters to put the semicolon to separate each of the emails I have. my SQL statement is like that SELECT Email FROM Customers WHERE newsletterAgree = "True" I am confused on how to start :confused:
-
but I am retrieving the numbers of emails using SQL statement which will be called using the button. which is then I need an array and delimiters to put the semicolon to separate each of the emails I have. my SQL statement is like that SELECT Email FROM Customers WHERE newsletterAgree = "True" I am confused on how to start :confused:
I suspect you may be starting to get way over your head here. You may need a contract developer to piece all this together.
StringBuilder sb = new StringBuilder();
using (SqlConnection conn = new SqlConnection("(replace this with a real connection string)"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT Email FROM Customers WHERE newsletterAgree = 1", conn))
{
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
sb.AppendFormat("{0};", rdr["Email"]);
}
}
}string finalString = sb.ToString();
If you want to convert finalString to an array, then once again, you need to do:
string[] finalArr = finalString.Split(';');
This should be compatible with all versions of ASP.NET
-
I want to use array to retrieve all the emails from my contacts for example. and i want to use delimiters to seperate all the emails with a semicolon ; and then i need to join them back as a string again to put it in a textbox. How do I do that? :confused: Urgent help is needed. Thank you
Since contents may have any type of symbols, I suggest that you convert it into Base64, and then you can use either comma or ';', or many other symbols as delimiters, from those that are not included into Base64 itself.