473,503 Members | 2,157 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Discerning what is a space in string..?

8 New Member
So, I'm trying to make a method that takes an input stream (from a text file), and churns out each word into it's own string, and sticks it into a list. According to my logic this should work, but (obviously) it doesn't. Any help would be appreciated :)

Expand|Select|Wrap|Line Numbers
  1. private void countWords()
  2.         {
  3.             bool isSpace;
  4.             count = 0;
  5.             //Will run as long as the files is real.
  6.             if (textFile != null)
  7.             {
  8.                 string line;
  9.                 StreamReader lines = new StreamReader(textFile);
  10.                 while ((line = lines.ReadLine()) != null)
  11.                 {
  12.                     //Makes sure the line isn't blank
  13.                     if (line.Trim().Length != 0)
  14.                     {
  15.                         isSpace = false;
  16.                         count++;
  17.                         //Adds to the count and adds to the list
  18.                         while(!isSpace)
  19.                         {
  20.                             if (string.Compare(line, blank) != 0)
  21.                             {
  22.                                 lines.Read();
  23.                                 line = line + lines;
  24.                             }
  25.                             else
  26.                             {
  27.                                 isSpace = true;
  28.                             }
  29.                         }
  30.                         randomOrder.Add(line);
  31.                     }
  32.                 }
  33.             }
  34.         }
Jan 26 '12 #1
3 1903
PsychoCoder
465 Recognized Expert Moderator Contributor
Can you define "This should work but it doesn't" please. Do you get an error? What does it do compared to what you need it to do.
Jan 26 '12 #2
Allwin Jeba
7 New Member
assign a space to a constant = " " and use that constant to find in your string. eg.

s.ToString().IndexOf(" ").
if you get any index there.. it means there is space..
Jan 27 '12 #3
Robert Hodan
8 New Member
@Richard McCutchen
What I'm trying to do is compare a string containing a space, to what I think (presuming I'm not using the streamreader wrong) should be the next character on a line. If the next character on the line is NOT a space, it adds it to the current string. When the string does hit a space, it adds the current word to a list, and continues, until it runs out of words.
However;
It freezes, gets trapped inside of this loop:

Expand|Select|Wrap|Line Numbers
  1. while(!isSpace)
  2.      {
  3.           if (string.Compare(line, blank) != 0)
  4.           {
  5.                lines.Read();
  6.                line = line + lines;
  7.           }
  8.           else
  9.           {
  10.               isSpace = true;
  11.           }
  12. }
Jan 27 '12 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
8384
by: Wayne Wengert | last post by:
In an ASP Page is there a way to have a link that calls another page whose name includes a space? For example, I'd like to be able to call "My Page.asp" by building a href type link the user can...
9
4466
by: Christopher Brandsdal | last post by:
Just a little question... How do I split 12345678 into 12 34 56 78??????? Christopher Brandsdal
4
3996
by: atse | last post by:
Hi, I have a string: mystring="1234,5678,985,21544,55524,11264, ... ," How can I divide this string into 1234 5678 985 .... 11264
4
4268
by: meldrape | last post by:
Hello, I need to parse a long string into no more than 30 character chunks, but I also need to leave the words intact. Right now, I am using: For intStart = 1 to Len(strOriginal) by 30...
8
4168
by: Joseph | last post by:
I have a textBox that people writes stories in it. They can use for format. I have Aspell installed on the server, so people can make correction to their text. Sometimes, they forget to add a...
7
1899
by: David Thielen | last post by:
Hi; This code is in J# so it looks a little weird but you could change it to C# in a couple of seconds. The problem here is a single space node returns as an empty node: public static void...
4
8775
by: Simon Schaap | last post by:
Hello, I have encountered a strange problem and I hope you can help me to understand it. What I want to do is to pass an array of chars to a function that will split it up (on every location where...
4
6859
by: Crirus | last post by:
There is a function somewhere to split a string with multiple tokens at a time? Say I have this: aaaa#bbbbb*ccccc$dddd I whould like to split it so the result whould be aaaa bbb
3
614
by: Kiran A K | last post by:
hi, can anybody give me a c# method that removes non-alphanumeric characters from a string? i would prefer it if the code uses regular expressions.
5
23444
by: SMichal | last post by:
Hi, how can I parse string "? 20.000" to double ?
0
7205
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7093
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7287
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7349
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5594
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3177
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
1521
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
746
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
399
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.