C# School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a C# Expert!

Join 307,153 C# Programmers for FREE! Get instant access to thousands of C# experts, tutorials, code snippets, and more! There are 1,631 people online right now. Registration is fast and FREE... Join Now!




ALERT! I am a beginner

 

ALERT! I am a beginner, hey i need help to get the correct syntax for counting the number of w

shruti86

27 Nov, 2008 - 01:26 AM
Post #1

New D.I.C Head
*

Joined: 27 Nov, 2008
Posts: 2

csharp

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter any sentence");
string s = Console.ReadLine();
for (int i=0; i=(s.Length -1);i++)
(if
)
Console.WriteLine(s);
Console.ReadLine();
}


Mod Edit: Please use code tags when posting your code. Code tags are used like so => code.gif

Thanks,
PsychoCoder smile.gif

User is offlineProfile CardPM
+Quote Post


ThekillingGoku

RE: ALERT! I Am A Beginner

27 Nov, 2008 - 07:18 AM
Post #2

New D.I.C Head
*

Joined: 13 Nov, 2008
Posts: 20



Thanked: 1 times
My Contributions
QUOTE(shruti86 @ 27 Nov, 2008 - 01:26 AM) *

namespace ConsoleApplication6
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("enter any sentence");
string s = Console.ReadLine();
for (int i=0; i=(s.Length -1);i++)
(if
)
Console.WriteLine(s);
Console.ReadLine();
}


The number of W's huh, well, let's start by making a char-array ... heheh, no seriously now,

I assume ya wanna count the number of words in any given string value depending on a delimiter which is also pretty simple using C#'s 'split' function.
You'll quickly find the intel ya need when ya check msdn and look for that function.
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo

RE: ALERT! I Am A Beginner

27 Nov, 2008 - 07:44 AM
Post #3

Not Your Ordinary Programmer
Group Icon

Joined: 21 Mar, 2008
Posts: 1,846



Thanked: 205 times
Dream Kudos: 500
Expert In: .NET

My Contributions
there is really no need in creating two topics. you are asking the same question that you asked in this topic...

http://www.dreamincode.net/forums/showtopic73764.htm

here is the answer I gave you there...

QUOTE(eclipsed4utoo @ 27 Nov, 2008 - 09:56 AM) *

fairly easy way is to split on a space and count the array elements.

csharp

Console.WriteLine("Enter a sentence");
string sentence = Console.ReadLine();

string[] wordArray = sentence.Split(new char[]{' '});

Console.WriteLine("Number of words in sentence is: {0}", wordArray.Length);

Console.ReadLine();




This post has been edited by eclipsed4utoo: 27 Nov, 2008 - 07:46 AM
User is online!Profile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 04:48PM

Live C# Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

C# Tutorials

Reference Sheets

C# Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month