Reading Strings and Conversion

  • (2 Pages)
  • +
  • 1
  • 2

19 Replies - 881 Views - Last Post: 03 February 2012 - 07:40 AM Rate Topic: -----

#1 Upstate518  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

Reading Strings and Conversion

Posted 02 February 2012 - 05:26 PM

I have to take the string "SUPERcalAFRAGiliSTICExpeALLEDocious” and decomposes the string so that the every three or five letters is printed on a different line starting with the last group and proceeding from the rear of the string to the front.

If the first letter of the group you are examining is lowercase, you should remove the next three letters and they should be converted to uppercase before printing. and vice versa.
If the first letter of the group is uppercase, you should remove the next five letters and they should be converted to lowercase.

I have a start but its not much, im confused as to how I examine all the different parts of the string and determine if the character is upper or lowercase

Heres my code thus far:

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

namespace StringManip
{
    class strings
    {
        static void Main()
        {
            string word = "SUPERcalAFRAGiliSTICExpeALLEDocious";
            string group;

            for (int pos = 0; pos < word.Length; pos++)
            {
                if (word == word.IsLower())
                {

                    group = word.Substring(word[pos], 4);
                    Console.WriteLine(group);

                }
                else
                {

                    group = word.Substring(word[pos], 2);
                    Console.WriteLine(group);
                }
                
                    
            }

        }
    }
}


Is This A Good Question/Topic? 0
  • +

Replies To: Reading Strings and Conversion

#2 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,943
  • Joined: 02-June 10

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:06 PM

Reminder to new folks: This is homework and we don't provide completed code for homework. Rather we try to help the student comprehend the concept they are struggling with so they can write their own code. They are being graded on their skill not ours.

This is the 'Help me with my homework' article you wanted.
Was This Post Helpful? 0
  • +
  • -

#3 Upstate518  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:09 PM

Yeah it is my homework, thats why im looking for help on it?
Was This Post Helpful? 0
  • +
  • -

#4 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,943
  • Joined: 02-June 10

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:12 PM

Please don't be offended but... you need to actually make a good faith effort at coding this to follow the instructions. Whacking out 45 seconds of a for..loop really what I would call a "good faith effort to solve the issue." It really doesn't even attempt to work according to the instructions:

Quote

last group and proceeding from the rear of the string to the front.

When you start at the front and work toward the back:

15 for (int pos = 0; pos < word.Length; pos++)


Let's talk about the logic of it:

You need to start at the last character and check if that character is upper or lower case. Keep working backwards until you find a character of the opposite case; tracking the position you started at.

Once you have found a character of the opposite case you know the sub-word is from where you are +1, to where you started.
Was This Post Helpful? 0
  • +
  • -

#5 Upstate518  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:16 PM

how would i test it though to determine whether its upper or lower case? thats my biggest issue
Was This Post Helpful? 0
  • +
  • -

#6 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,943
  • Joined: 02-June 10

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:19 PM

17 if (word == word.IsLower())

Huh? Are you just making up methods as you go along hoping they might exist?

Where did you get ".IsLower()" from? There is no such method in the string class.

Attached Image

Is it possible you meant ".ToLower()" ?
Was This Post Helpful? 0
  • +
  • -

#7 Upstate518  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:21 PM

yeah i meant to lower, im just having trouble testing each individual character for its case through the string
Was This Post Helpful? 0
  • +
  • -

#8 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,943
  • Joined: 02-June 10

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:22 PM

View PostUpstate518, on 02 February 2012 - 08:16 PM, said:

how would i test it though to determine whether its upper or lower case? thats my biggest issue


I'm trying to remain polite and helpful, so please forgive how this sounds.
If the lesson is on the case of characters and strings, then I'd bet this was covered in class lecture or possibly in your textbook. They don't just throw you to the wolves and ask you to do things they didn't teach/cover in class as well as not covered in the book.

Here is the MSDN page on String.ToLower()
http://msdn.microsof...y/e78f86at.aspx
Was This Post Helpful? 0
  • +
  • -

#9 Upstate518  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:24 PM

i tried this:

if(word[pos]==word.ToLower)



but that did not work

give me a break its my second semester of programming
Was This Post Helpful? 0
  • +
  • -

#10 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,943
  • Joined: 02-June 10

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:24 PM

View PostUpstate518, on 02 February 2012 - 08:21 PM, said:

yeah i meant to lower, im just having trouble testing each individual character for its case through the string


So you meant .ToLower().... Which means the code you provided to get help on won't compile or run. It would produce an error letting you know that no such method exists.
Was This Post Helpful? 0
  • +
  • -

#11 Upstate518  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:25 PM

Yeah I know... thats why I came here looking for help
Was This Post Helpful? 0
  • +
  • -

#12 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,943
  • Joined: 02-June 10

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:35 PM

View PostUpstate518, on 02 February 2012 - 08:24 PM, said:

i tried this:

if(word[pos]==word.ToLower)



but that did not work

give me a break its my second semester of programming


Second SEMESTER ? So you've been in this course for 4 months? And somehow you are trying to compare a single character to the entire word and expecting it could somehow match?

In your example the first time through the loop you are checking this:

if (s == "SUPERcalAFRAGiliSTICExpeALLEDocious".ToLower())
{
    // then do this
}


Ummm... I don't even know where to go or what to say from here.

If this is where you are going on 4-5 months into this course you really need to seek out your instructor and ask about tutoring so you can get caught up. You cannot continue to bluff your way through the course in the hopes that it is going to spontaneously start making sense in a couple more weeks.

I'm not trying to stop you from coding. Or demoralize you. I want you to code. But it is very very clear you need some help to get caught up. I want to see you learn, not throw away your tuition money.

I will point out that you aren't required to only learn from the course textbook. There are numerous self-teaching books that would have you a lot further along than playing with string case after about 4 days instead of 4 months. As well as an entire internet full of tutorials and on-line self-teaching resources. You can use them in conjunction with your course textbook and professor.




Resources, references and suggestions for new programmers. - Updated Jan 2012
Spoiler

Was This Post Helpful? 0
  • +
  • -

#13 superkb10  Icon User is offline

  • D.I.C Regular

Reputation: 29
  • View blog
  • Posts: 298
  • Joined: 27-November 11

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:36 PM

Hey, I'm pretty new to C#, but I'm fairly certain that ToLower() doesn't tell you whether or not the character/string is uppercase or lowercase, but more rather converts the entire string to lowercase. ToLower() is usually used when someone wishes to ignore case.

Of course I could be entirely wrong, as once again, I'm fairly new to C# and programming in general.
Was This Post Helpful? 0
  • +
  • -

#14 Upstate518  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 02-February 12

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:40 PM

its the second week of the class, and my second week of programming in c#. I did c++ before, all i did was ask for some help on how to do it and your just trying to make me look like a fool.
Was This Post Helpful? 0
  • +
  • -

#15 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5583
  • View blog
  • Posts: 11,943
  • Joined: 02-June 10

Re: Reading Strings and Conversion

Posted 02 February 2012 - 07:53 PM

I'm not looking to make you out to be a fool. It's just hard to know where to begin to help someone when they are asking for help on methods that don't exist. Where would you start trying to help someone if they asked for help on how to unbuckle a seatbelt when the pullcord didn't work? You'd be wondering... "The pull cord?? WTF?"

Effectively this means you were trying to pass off code that won't compile as code you've been working really hard on before finally giving up and asking for help. Since we're not idiots here we know it won't run. Which means we know you've got all of 60 seconds into that before asking others to help.

Before I go to bed I'm going to point out that just as you learned in C++, not every single solitary possibility you could ever need has been pre-written for you to just use. You might, just maybe, have to use a little bit of thought about how to combine things to form what we in the developer world call... Logic.

If (word[pos] == word[pos].ToLower)
{
   // Then the character at position is LowerCase
}


Please forgive my tone. Its late. I have a crappy attitude. And I don't have my customary level of tolerance.

Programming is basically solving brain teasers through code. That's what the job is. That is what you can look forward to if you pursue this as a career. If you don't enjoy and excel at unwrapping a puzzle, turning it on its head, seeing it from numerous perspectives to CREATE a solution... rather than trying to find the pre-made command to solve it... well...

Again... Sorry for my having a pissy attitude.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2