Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Combining Array with delimiters

Combining Array with delimiters

Scheduled Pinned Locked Moved ASP.NET
questiondata-structureshelptutorial
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • F Offline
    F Offline
    Fiona Tan
    wrote on last edited by
    #1

    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

    T V 2 Replies Last reply
    0
    • F Fiona Tan

      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

      T Offline
      T Offline
      thoiness
      wrote on last edited by
      #2

      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();

      F 2 Replies Last reply
      0
      • T thoiness

        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();

        F Offline
        F Offline
        Fiona Tan
        wrote on last edited by
        #3

        after recreating the string how do I store it into the textbox?

        T 1 Reply Last reply
        0
        • F Fiona Tan

          after recreating the string how do I store it into the textbox?

          T Offline
          T Offline
          thoiness
          wrote on last edited by
          #4

          NameOfTextBox.Text = rebuiltString;

          1 Reply Last reply
          0
          • T thoiness

            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();

            F Offline
            F Offline
            Fiona Tan
            wrote on last edited by
            #5

            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:

            T 1 Reply Last reply
            0
            • F Fiona Tan

              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:

              T Offline
              T Offline
              thoiness
              wrote on last edited by
              #6

              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

              1 Reply Last reply
              0
              • F Fiona Tan

                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

                V Offline
                V Offline
                Vitaly Tomilov
                wrote on last edited by
                #7

                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.

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups