Hello Friends
Its sajid here and i am new to C#. i have a query in C#
what i want to do is Read a file that contains some text. i want to read text word by word and and store those words in an array and then print all those words in array in a list box or drop down..
Please help
Thanks..
Loading

Kirtan PatelPosted Mar 28, 2012, 10:06 AM
SenthilkumarPosted Mar 27, 2012, 11:32 PM
I have tested and its working fine. Please try the following.
If this helps you to get the answer then mark it as "Accepted Answer"
VulpesPosted Mar 27, 2012, 5:31 PM
You can use the string's indexer to pick out the character at a particular index (starting from 0).
So, if you have this string:
string s = "$ab = 2;";
then:
char c0 = s[0]; // $
char c1 = s[1]; // a
char c2 = s[2]; // b
You can also convert a string to a char array:
char[] chars = s.ToCharArray();
or iterate through the characters one by one:
string message = "";
foreach(char c in s) message += c.ToString() + "\r\n";
MessageBox.Show(message); // displays characters vertically from top
sajid rajaPosted Mar 27, 2012, 5:04 PM
Can you please tell me how can i read string character by character,,
i am having a university project as.
i have to read data some what like
$ab = 2;
$bc = "Some string";
$xyz= 'A' // Some character
I want to read $ a b one by one...
VulpesPosted Mar 27, 2012, 4:50 PM
then this revised code should work:
sajid rajaPosted Mar 27, 2012, 4:29 PM
Many thanks for your reply..
but i have tried this..
if I have following text in file
The quick brown fox jumps over the lazy dog
then it works ok..
But when i Put some more text in a new line in file then it is not working Ok
It is splitting only first line in file..
VulpesPosted Mar 27, 2012, 4:16 PM
Suppose for example the file contains the following sentence:
The quick brown fox jumps over the lazy dog
Then you could load the file, split it into words and display them in a ListBox in a Windows Forms application with the following code: