• Advertisement
Sign in to follow this  

[.net] Coverting a String into a Char Array

This topic is 4358 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I've read a file into a stream. Now i want to convert the stream in to a Char Array so that i can work on the values at individual indexes in the array. I've tried everything but I still cannot convert the stream into an array. Please Help. Thank you.

Share this post


Link to post
Share on other sites
Advertisement
In the topic title you mentioned convertiong a sting to a char array. in your post you want to convert a stream type to a char array, that makes no sense.
the easiest way to read a file into a string is:

System.IO.StreamReader sr = new System.IO.StreamReader("file"); //create a StreamReader object, that opens a file or a stream for reading

string str;
sr.ReadToEnd(str); //read the whole content (from current read position) of the stream into the string
sr.Close(); //close the stream when finished reading data
char ch = str[0]; //access the elements of the string (characters) with the index operator. of course you cannot index further than the length of the string (str.Length)

ps.: a string is an array of chars ;) why would you convert it?

Share this post


Link to post
Share on other sites
I'm sorry, I wanted to write that I've copied a stream in to string and now wanted to convert it to a Char Array. Anyway,it's resolved now. Thanks for the help.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement