Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
1.00/5 (1 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?
Sergey Alexandrovich Kryukov 22-Mar-13 3:15am    
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)
{
}
}

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

And you list has the method ToArray.

Is the case closed?

—SA
 
Share this answer
 
Comments
Arsalaan Ahmed 22-Mar-13 3:24am    
No,,
Sergey Alexandrovich Kryukov 22-Mar-13 3:32am    
Huh?
—SA
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

C#
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

C#
  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>
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900