Click here to Skip to main content
14,304,368 members
Rate this:
Please Sign up or sign in to vote.
See more:
how to convert character list into string list in C#?
Posted
Comments
Steve44 22-Mar-13 3:08am
   
Please provide more detail so we can answer your question. How is the character list stored? How do you want the string (list?) to look like after conversion?
   
What did you try so far? How can it be a problem?
-SA
Arsalaan Ahmed 22-Mar-13 3:16am
   
character store on character list. i have a character array i am store character by character into character list ,,, if whitespace will come in my string so all readable character save string list index[0].... how to do this,,,,
example:
string = "void main"
charater array read character by character and store in character list and space will come.
then this step perform
void save in string list on index zero,,
Arsalaan Ahmed 22-Mar-13 3:20am
   
here is a code:-
char[] letter = new char[50];
string asa;
int y = 0;
List<char> optionList = new List<char>();
List<string> temp = new List<string>();
char[] array = ar.ToCharArray();

for (int i = 0; i <= text.Length - 1; i++)
{
if (array[i] == ' ')
{
temp = new List<string> {(optionList).ToString()};
foreach (string asaaa in temp)
{
Console.WriteLine(temp[0]);
}
else
{
try
{

letter[i] = array[i];
optionList[i] = Convert.ToChar(letter[i]);
Console.WriteLine(optionList[0]);
y++;
}
catch(Exception ex)
{
}
}
Rate this:
Please Sign up or sign in to vote.

Solution 1

Start from here: http://msdn.microsoft.com/en-us/library/ttyxaek9.aspx[^].

And you list has the method ToArray.

Is the case closed?

—SA
   
Comments
Arsalaan Ahmed 22-Mar-13 3:24am
   
No,,
   
Huh?
—SA
Rate this:
Please Sign up or sign in to vote.

Solution 2

Hi,
Can you provide detail. What do you mean by string List (string is array of characters).

If you talking about to convert character array in string

char[] charAray = new char[] {'h','e','l','l','o' };
string mystring = new string(charAray);



If you need to convert char array into string array, then you have many solutions like iterations.
I recommend you to create an extension method, which can parse source into target type.
For more detail here is generic extension method for your reference

  public static class Extensions
    {
        public static List<t> ToList<t>(this IEnumerable source) where T : class
        {
            List<t> collection = new List<t>();

            foreach (var x in source)
            {
                T info = Convert.ChangeType(x, typeof(T)) as T;
                collection.Add(info);
            }

            return collection;
        }
    }


//////////////////////////////////////////////////////////////////

char[] charAray = new char[] {'h','e','l','l','o'};
List<string> strList = charAray.ToList<string>();

</string></string></t></t></t></t>
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100