473,396 Members | 1,879 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Write a program in C#

I need to write a program that will total the integer values of each characters in a string not including spaces. The program should produce two totals. First should be a fixed string, second should using an empty string of 80 charact. max lenght, using both alphanumeric and numeric characters. I'am fresh in this so please help me. Can you give me any clue!?

using System;
using System.Collections.Generic;
using System.Text;


class Program
{
public static void Main(string[] args)
{
string str = " The quick red fox jumped over the lazy brown dog";
string str1 = "My mother will finish 40 years soon";
int liczba = str.Remove(' ').Length;
int liczba1 = str1.Length;
int totalcount = 0;
int totalcount1 = 0;

foreach (char ch in str)
totalcount++;
Console.WriteLine(" There are {0} characters in strig:\n{1}\n", liczba.ToString(), str);



foreach (char a in str1)
if (Char.IsDigit(a))
totalcount1++;
Console.WriteLine(" There are {0} characters in strig:\n{1}", liczba1.ToString(), str1);
Console.WriteLine(" Oh no a digit" + " has been found ");

}
}

I don't know how to count in the second sentence, how many characters there are without spaces. When I put: int liczba1 = str1.Remove(' ').Length; the program can't build solution.Thanks
Aug 20 '07 #1
5 1576
Plater
7,872 Expert 4TB
Don't double post.
http://www.thescripts.com/forum/thread693383.html

You were already being helped there but you never came back.
Aug 20 '07 #2
Don't double post.
http://www.thescripts.com/forum/thread693383.html

You were already being helped there but you never came back.
next code:

using System;
using System.Collections.Generic;
using System.Text;


class Program
{
public static void Main(string[] args)
{
string str = " The quick red fox jumped over the lazy brown dog";
string str1 ;
int liczba = str.Remove(' ').Length;

int totalcount = 0;
int totalcount1 = 0;

foreach (char ch in str)
totalcount++;
Console.WriteLine(" There are {0} characters in strig:\n{1}\n", liczba.ToString(), str);
Console.WriteLine("--------------------------");
Console.WriteLine("Write the next sentence: ");
str1= Console.ReadLine();
int liczba1 = str1.Length;

foreach (char a in str1)
if (Char.IsDigit(a))
totalcount1++;
Console.WriteLine(" There are {0} characters in strig:\n{1}", liczba1.ToString(), str1);
Console.WriteLine(" Oh no a digit" + " has been found ");

}
}
Aug 20 '07 #3
next code:

using System;
using System.Collections.Generic;
using System.Text;


class Program
{
public static void Main(string[] args)
{
string str = " The quick red fox jumped over the lazy brown dog";
string str1 ;
int liczba = str.Remove(' ').Length;

int totalcount = 0;
int totalcount1 = 0;

foreach (char ch in str)
totalcount++;
Console.WriteLine(" There are {0} characters in strig:\n{1}\n", liczba.ToString(), str);
Console.WriteLine("--------------------------");
Console.WriteLine("Write the next sentence: ");
str1= Console.ReadLine();
int liczba1 = str1.Length;

foreach (char a in str1)
if (Char.IsDigit(a))
totalcount1++;
Console.WriteLine(" There are {0} characters in strig:\n{1}", liczba1.ToString(), str1);
Console.WriteLine(" Oh no a digit" + " has been found ");

}
}
I can only apologize for last one. I still have a problem with this code
Aug 20 '07 #4
Plater
7,872 Expert 4TB
Well string.Remove() wants an index not a character type that you want to remove.
You would be looking for .Replace(" ","");

But this is still the same thing as before.
And still seems like homework.
Aug 20 '07 #5
Well string.Remove() wants an index not a character type that you want to remove.
You would be looking for .Replace(" ","");

But this is still the same thing as before.
And still seems like homework.
I'm study, and I have some problems, this C# it is difficult, but I'm not gonna give up on this.
Thanks for your help!!!
Aug 20 '07 #6

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

Similar topics

33
by: Nick Evans | last post by:
Hello there, I have been on and off learning to code (with python being the second language I have worked on after a bit of BASIC). What I really want to know is, if you are going to actually...
6
by: rxl124 | last post by:
someone please please help w/ this one. As I been working on this on and off and it just does not want to work. 1 #!/usr/bin/perl -w 2 3 $file = "/home/user1/dothis"; 4 open(FILE, ">$file");...
8
by: Zheng Da | last post by:
I don't know where should I ask the question, so send the email to this group. I choose this group, because I want to write the program with c++ :) I want to write a program which support...
24
by: gswork | last post by:
Let's write a c program, without knowing what it does... Some of you may recall Jim Roger's excellent series of posts (on comp.programming) exploring the implementation of common software...
24
by: Charles Ulrich | last post by:
Greetings, I hope my greenness isn't showing too bad by asking this, but I ran across this trivial program today that left me flabbergasted: #define MESSAGE "This account is currently not...
18
by: jacob navia | last post by:
In C, we have read-only memory (const), read/write memory (normal data), and write only memory. Let's look at the third one in more detail. Write only memory is a piece of RAM that can only...
4
by: Break2 | last post by:
I am trying to write a simple program which asks a user to enter 5 integers after which the average will be computed and written to the screen. That simple. However I want to do it according to a...
1
by: Sachin Garg | last post by:
I have a program which opens a fstream in binary input+output mode, creating the file if it doesn't exists. But writing doesn't works after reading, it must be something obvious that I am not aware...
5
by: Jon Skeet [C# MVP] | last post by:
On Sep 9, 9:41 am, raylopez99 <raylope...@yahoo.comwrote: It's tricky in .NET for two reasons: 1) LINQ doesn't have any concept of "remove" 2) List<T>.RemoveAll doesn't pass in the index...
11
by: 960392954 | last post by:
The Towers of Hanoi is a famous problem about moving a certain number of disks from one peg to another.I write a recursive program for it.If you have known it ,you can skip the program. #include...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.