---
title: "How can I divide a set of strings into their constituent characters in C#?"  
description: "How can I divide a set of strings into their constituent characters in C#?"  
author: "Anonymous User"  
published: 2013-06-06  
updated: 2013-06-06  
canonical: https://www.mindstick.com/forum/1004/how-can-i-divide-a-set-of-strings-into-their-constituent-characters-in-c-sharp  
category: "c#"  
tags: ["c#"]  
reading_time: 2 minutes  

---

# How can I divide a set of strings into their constituent characters in C#?

Hi [Expert](https://www.mindstick.com/articles/13120/an-expert-financial-advice-will-improve-your-finances),\
What is the best way to separate the individual [characters](https://answers.mindstick.com/qa/42112/who-is-the-originator-of-avengers-characters) in an [array of strings](https://www.mindstick.com/forum/158840/create-a-rust-program-to-sort-an-array-of-strings-in-lexicographical-order) **strArr** into an array of those characters **charArr**, as depicted below?

```
string[] strArr = { "123", "456", "789" };char[] chrArr = { '1', '2', '3', '4', '5', '6', '7', '8', '9' };This is what I am currently doing, but I do not think that it is very elegant:int characterCount = 0;for (int i = 0; i < strArr.Length; i++){    characterCount += strArr[i].Length;}int indexCount = 0;char[] chrArr = new char[characterCount];for (int i = 0; i < strArr.Length; i++){    for (int j = 0; j < strArr[i].Length; j++)    {        chrArr[indexCount] = strArr[i][j];        indexCount++;    }}
```

\
Please help,Thanks in advance.

## Replies

### Reply by AVADHESH PATEL

Hi,\
Well, easiest way would be this:\
char[] chrArr = string.Join(string.Empty, strArr).ToCharArray();To make sure there is no confusion over performance characteristics here, here is a short program to test in LINQPad (don't forget to turn on optimizations in the lower right corner):\

```
static string[] strArr = { "123", "456", "789" };void Main(){    const int iterations = 10000000; // 10 million    // Warm up JITter    StringJoin();    LINQSelectMany();    LINQ();    Stopwatch sw = Stopwatch.StartNew();    for (int index = 0; index < iterations; index++)        StringJoin();    sw.Stop();    sw.ElapsedMilliseconds.Dump("String.Join");    sw.Restart();    for (int index = 0; index < iterations; index++)        LINQSelectMany();    sw.Stop();    sw.ElapsedMilliseconds.Dump("LINQ SelectMany");    sw.Restart();    for (int index = 0; index < iterations; index++)        LINQ();    sw.Stop();    sw.ElapsedMilliseconds.Dump("LINQ");}public static void StringJoin(){    char[] c = string.Join(string.Empty, strArr).ToCharArray();}public static void LINQSelectMany(){    char[] c = strArr.SelectMany(s => s).ToArray();}public static void LINQ(){    var characters = (from s in strArr                      from c in s                      select c).ToArray();}
```

**You can download this LINQPad script here if you want to play with it.****\****Output (in milliseconds):****\**String.Join 765 **\****LINQ SelectMany** **5098** **\****LINQ** **5465** **\**I hope it helpful for you.


---

Original Source: https://www.mindstick.com/forum/1004/how-can-i-divide-a-set-of-strings-into-their-constituent-characters-in-c-sharp

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
