1,105,254 Community Members

console app that converts uppercase to lower and vice versa

Member Avatar
king03
Junior Poster
183 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

Hi there guys I need your help so badly as I can't finish my program. The instructions are: create a console application that instantiates a class with a method that takes in a string of values converts upper case to lower case and vice versa. The method also returns the string without special characters. Place your code in a short bond paper.

Method Name: ChangeCase
Class Name: Casing

Here's an example input and output:

INPUT: In$p!red4Progr@mming

OUTPUT: iNPRED4pROGRMMING

Use method: isupper, islower, isdigit etc.

Here what I've accomplished so far (Our professor said my draft is already correct but it still doesn't have any content just how the code is supposed to look like, this is like the skeleton of the program and also I'm not yet done with my loop because I don't know what to put inside... Please Help me)

Here's my code:

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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            Casing c = new Casing(Console.ReadLine());

            Console.WriteLine(c.Value);

            Main();
        }
    }
    class Casing
    {
        private string sValue;

        public string Value
        {
            get { return sValue; }
            set { sValue = value; }
        }

        public Casing(){}
        public Casing(string value)
        {
            Value = ChangeCase(value);
        }

        public string ChangeCase(string value)
        {
            string changedValue ="";

            for (int i = 0; i < value.Length; i++)
            {
Member Avatar
ddanbe
Posting Expert
5,336 posts since Oct 2008
Reputation Points: 2,054 [?]
Q&As Helped to Solve: 904 [?]
Skill Endorsements: 46 [?]
Featured
 
0
 

Why are you calling Main in yourMain method on line 16?
Tip: have a look at this:http://msdn.microsoft.com/en-us/library/system.char.isletter(VS.71).aspx

Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
0
 

You have way too much code and adding a class is too complicated for what you are doing. If you're using Visual Studio, start over with a clean project, compile it before doing anything else and then think about the problem.

Think character-array and characters.

Member Avatar
DaveAmour
Newbie Poster
15 posts since Apr 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

A class is needed - this is an academic piece of work and the instructions say to use a class. Always follow the instructions if you want good marks!

Member Avatar
DaveAmour
Newbie Poster
15 posts since Apr 2010
Reputation Points: 0 [?]
Q&As Helped to Solve: 1 [?]
Skill Endorsements: 0 [?]
 
0
 

Also where is the rest of your code and do your instructions give a definition for special characters?

Member Avatar
king03
Junior Poster
183 posts since Mar 2011
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

anyone here guys who can show me how to do the upper case and lower case conversion? any tips? thanks in advance for those who will help I would really appreciate it.

Member Avatar
hericles
Veteran Poster
1,078 posts since Nov 2007
Reputation Points: 98 [?]
Q&As Helped to Solve: 232 [?]
Skill Endorsements: 14 [?]
Featured
 
0
 

If you want a quick and dirty solution, break your input into a character array and loop through it. For each character check if it isDigit(), if yes no change is required. Then check for the special characters you need to remove. Lastly check isUpper for the character. If false use toUpper, if true use toLower to convert them.
In some simple but ugly pseudo code:

if(isDigit){
   add to output string
} else if(isSpecial) {
  do not add to output string
} else if(isUpper) {
  character.toLower()
  add to output string
} else {
  character.toUpper()
  add to output string
}
Member Avatar
thines01
Postaholic
2,420 posts since Oct 2009
Reputation Points: 389 [?]
Q&As Helped to Solve: 413 [?]
Skill Endorsements: 10 [?]
Team Colleague
Featured
 
0
 

Inside your ChangeCase method, I would convert the string to a CharArray then iterate over each character and evaluate (with the isDigit(), isLower(), etc).

If you can use a StringBuilder, please do. Use the Append method to piece together the characters you can keep. ...and return the StgringBuilder as a string.

Please let me know if this is not clear.

Member Avatar
Momerath
Senior Poster
3,822 posts since Aug 2010
Reputation Points: 1,323 [?]
Q&As Helped to Solve: 661 [?]
Skill Endorsements: 19 [?]
Featured
 
0
 

Inside your ChangeCase method, I would convert the string to a CharArray

There is no need to do this. You can treat a String as if it was already a character array.

using System;

namespace ConsoleApplication1 {
    class Program {
        static void Main(string[] args) {
            String test = "this is a test string";
            foreach (char c in test) {
                Console.Write("{0}-", c);
            }

            Console.WriteLine();
            for (int i = 0; i < test.Length; i++) {
                Console.Write("{0}-", test[i]);
            }
            Console.WriteLine();

            Console.ReadLine();
        }
    }
}
Member Avatar
duke_swh
Newbie Poster
8 posts since Jul 2010
Reputation Points: -2 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
-1
 

here is a piece of code you can use in your method:

string s = inputstring;
            string output = "";
            char a;
            foreach (char c in s)
            {
                if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9'))
                {
                    if (Char.IsDigit(c))
                    {
                        output += c;
                    }
                    else if (Char.IsUpper(c))
                    {
                      a =  Char.ToLower(c);
                        output += a;
                    }
                    else if (Char.IsLower(c))
                    {
                     a =   Char.ToUpper(c);
                        output += a;
                    }
                }
            }
            return output;
You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
View similar articles that have also been tagged: