Results 1 to 4 of 4

Thread: [2.0] 5 character string array?

  1. #1

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    [2.0] 5 character string array?

    i have a text box that contains a string. The strings length is always a multiple of 5. How can i break the string into chunks of 5 and store them in a string arrary?

  2. #2
    PowerPoster
    Join Date
    Aug 2003
    Location
    Edinburgh, UK
    Posts
    2,773

    Re: [2.0] 5 character string array?

    if there is a special character to endicate the end of 1 5 char block then:


    Code:
    string[] theChunks = this.TextBox1.Text.Split(someIndicator);
    or you could go through each character and return it the 5 characters per chunk of 5 characters

    if I understood that correctly....

    MVP 2007-2010 any chance of a regain?
    Professional Software Developer and Infrastructure Engineer.

  3. #3

    Thread Starter
    Hyperactive Member francisstokes's Avatar
    Join Date
    May 2005
    Location
    Kent, England
    Posts
    272

    Re: [2.0] 5 character string array?

    No there is no seperator. Ill give your second answer a try.

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: [2.0] 5 character string array?

    Code:
    string text = this.textBox1.Text;
    int chunkCount = text.Length / 5;
    string[] chunks = new string[chunkCount];
    int startIndex = 0;
    
    for (int i = 0; i < chunks.Length; i++)
    {
        chunks[i] = text.Substring(startIndex, 5);
        startIndex += 5;
    }
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width