Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. previous post is got too long, isn't it? (my previous question again)

previous post is got too long, isn't it? (my previous question again)

Scheduled Pinned Locked Moved C#
questionhelp
30 Posts 9 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Sajjad Izadi

    thanks for your answer but 'foreach' and indexes are not allowed to use, too. but i think when our teacher askes such questions, there should be a solution.

    P Offline
    P Offline
    Paul Conrad
    wrote on last edited by
    #19

    Sajjad Izadi wrote:

    i think when our teacher askes such questions, there should be a solution.

    Could it be your teacher is an idiot?

    "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

    1 Reply Last reply
    0
    • C Christian Graus

      He's not allowed to use foreach, I assume that means when he says he's not allowed to use [], he means at all, not just on the string class. I bow to you, that just didn't occur to me, or anyone else. I wonder if the goal is to fail anyone who gets the answer, b/c they must have asked on the web to get it ?

      Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

      P Offline
      P Offline
      Paul Conrad
      wrote on last edited by
      #20

      Maybe, but the teacher should be a bit more clear and should give the students a hint, such as "you may want to look at the stringbuilder class" :rolleyes:

      "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

      C 1 Reply Last reply
      0
      • L Luc Pattyn

        Christian Graus wrote:

        it plain cannot be done.

        Hmm. All it takes is StringBuilder class, with one of its constructors (string), and ToString(). :)

        Luc Pattyn [Forum Guidelines] [My Articles]


        Voting for dummies? No thanks. X|


        P Offline
        P Offline
        Paul Conrad
        wrote on last edited by
        #21

        Five for you. I didn't even think of the StringBuilder class :-O

        "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

        1 Reply Last reply
        0
        • P Pete OHanlon

          OK - I'm interested. Type in the EXACT text of the assignment so we can all marvel at this. You've got a site full of professional developers here all telling you that this can't be done so at least one of the following conditions applies: a) your understanding is wrong b) this is the wrong forum and you are meant to be using a language like C c) you have missed out a vital step or two d) your professor is a complete thundering idiot and the assignment is wrong e) you are way off beam with the foreach/indexer idea Let's have a look so we can make our own mind up.

          Deja View - the feeling that you've seen this post before.

          My blog | My articles

          P Offline
          P Offline
          Paul Conrad
          wrote on last edited by
          #22

          Me thinks there is some missing details in the OP...

          "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

          1 Reply Last reply
          0
          • C Christian Graus

            I think Luc found the answer. I can't imagine what the goal of this assignment was, in terms of learning something, but apparently, you can pass a string into a stringbuilder and use the stringbuilder to pull out substrings, and get the string length. You can use another stringbuilder to build a new string. So, ultimately, the only thing I can think of, is that the professor hoped to create some research skills, or something.

            Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

            P Offline
            P Offline
            Paul Conrad
            wrote on last edited by
            #23

            Christian Graus wrote:

            the professor hoped to create some research skills

            I hope that is the case. That is, to me, of more value than the ability to hack out the code for the assignment. This opens up the student to stronger analytical thinking skills/think-outside-the-box, etc.

            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

            1 Reply Last reply
            0
            • P Paul Conrad

              Maybe, but the teacher should be a bit more clear and should give the students a hint, such as "you may want to look at the stringbuilder class" :rolleyes:

              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

              C Offline
              C Offline
              Christian Graus
              wrote on last edited by
              #24

              Oh, the assignment is useless. I think the main reason none of us got it is b/c it's not clear how you'd expect that to involve a learning objective. What do they learn from that ?

              Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

              P 1 Reply Last reply
              0
              • C Christian Graus

                OK - so you have to assume that my answer was right. You CAN use foreach, and you can use []. If you can't, then the question does not say that, AND, without those, it plain cannot be done.

                Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

                L Offline
                L Offline
                Luc Pattyn
                wrote on last edited by
                #25

                An alternative, more adventurous, but all in all easier way is to use P/Invoke and some native C code, so strlen, strcat, and the like can be used (they are not part of the String class!). Now the input data can get passed down as string, and a sufficiently large StringBuilder should be passed too to collect the resulting string, so ToString() can upgrade them to the final result. This way the exercise makes some sense. :)

                Luc Pattyn [Forum Guidelines] [My Articles]


                Voting for dummies? No thanks. X|


                1 Reply Last reply
                0
                • C Christian Graus

                  Oh, the assignment is useless. I think the main reason none of us got it is b/c it's not clear how you'd expect that to involve a learning objective. What do they learn from that ?

                  Christian Graus Please read this if you don't understand the answer I've given you. If you're still stuck, ask me for more information.

                  P Offline
                  P Offline
                  Paul Conrad
                  wrote on last edited by
                  #26

                  Christian Graus wrote:

                  the assignment is useless

                  Yes. It was very pointless, and it is not something I would subject my students to.

                  Christian Graus wrote:

                  What do they learn from that ?

                  Not sure, other than to try and get other people to do their work for them. That is why I suggested the teacher should have given some kind of hint.

                  "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon

                  1 Reply Last reply
                  0
                  • L Luc Pattyn

                    Christian Graus wrote:

                    it plain cannot be done.

                    Hmm. All it takes is StringBuilder class, with one of its constructors (string), and ToString(). :)

                    Luc Pattyn [Forum Guidelines] [My Articles]


                    Voting for dummies? No thanks. X|


                    G Offline
                    G Offline
                    Guffa
                    wrote on last edited by
                    #27

                    Luc Pattyn wrote:

                    All it takes is StringBuilder class, with one of its constructors (string), and ToString().

                    Oh, circumventing the rule that no methods of the string class should be used, by using methods of another class... Sneaky... ;) Then there are some other alternatives to get at the data, like using the Encoding.UTF16.GetBytes method, or use a StreamWriter to write the string to a MemoryStream...

                    Despite everything, the person most likely to be fooling you next is yourself.

                    L 1 Reply Last reply
                    0
                    • G Guffa

                      Luc Pattyn wrote:

                      All it takes is StringBuilder class, with one of its constructors (string), and ToString().

                      Oh, circumventing the rule that no methods of the string class should be used, by using methods of another class... Sneaky... ;) Then there are some other alternatives to get at the data, like using the Encoding.UTF16.GetBytes method, or use a StreamWriter to write the string to a MemoryStream...

                      Despite everything, the person most likely to be fooling you next is yourself.

                      L Offline
                      L Offline
                      Luc Pattyn
                      wrote on last edited by
                      #28

                      Guffa wrote:

                      Oh, circumventing the rule that no methods of the string class should be used, by using methods of another class... Sneaky...

                      Yeah, what's the use of .NET if you're not allowed to use any class method? :confused: And if that is what it takes to answer a question, then probably the question itself is sneaky. I can't help that. :)

                      Luc Pattyn [Forum Guidelines] [My Articles]


                      Voting for dummies? No thanks. X|


                      1 Reply Last reply
                      0
                      • S Sajjad Izadi

                        do you know what the question is infact? the question is to make the following methods without using prepared methods in String Class and operators += and +:

                        public String delete (String st, int startIndex, int len); //delete part of a string and return the result

                        public String copy (String st, int startIndex, int len); //copy a subString from startIndex till len and return the result

                        public String insert (String st1, String st2, int len); //insert a string to an other

                        public String concat (String st1, String st2); //concat two strings

                        public int pos (String st1, String st2, int len); //return the position of specified string in an other specified string

                        public int countOf (String st1, String st2, int len); //return number of repetitions of an string in an other string

                        public String intToStr(int value); //make an integer to string

                        public int strToInt (String value); //make a string to an integer

                        public String reverse (String value); //return the reversed

                        how can i answer to these question with considering the condition? please help me and as you guessed it's a school homework. thank you

                        G Offline
                        G Offline
                        Guffa
                        wrote on last edited by
                        #29

                        Seems like there is some information missing... Do you have any specification what the methods should do, really?

                        Sajjad Izadi wrote:

                        public String insert (String st1, String st2, int len); //insert a string to an other

                        What is the len parameter supposed to do? Where in one of the strings (which?) is the other supposed to be inserted?

                        Sajjad Izadi wrote:

                        public int pos (String st1, String st2, int len); //return the position of specified string in an other specified string

                        What is the len parameter supposed to do?

                        Sajjad Izadi wrote:

                        public int countOf (String st1, String st2, int len); //return number of repetitions of an string in an other string

                        What is the len parameter supposed to do? Can the occurances of the string overlap, i.e. should countOf("aba", "ababa", whatever) return one or two?

                        Despite everything, the person most likely to be fooling you next is yourself.

                        1 Reply Last reply
                        0
                        • P Pete OHanlon

                          OK - I'm interested. Type in the EXACT text of the assignment so we can all marvel at this. You've got a site full of professional developers here all telling you that this can't be done so at least one of the following conditions applies: a) your understanding is wrong b) this is the wrong forum and you are meant to be using a language like C c) you have missed out a vital step or two d) your professor is a complete thundering idiot and the assignment is wrong e) you are way off beam with the foreach/indexer idea Let's have a look so we can make our own mind up.

                          Deja View - the feeling that you've seen this post before.

                          My blog | My articles

                          L Offline
                          L Offline
                          leppie
                          wrote on last edited by
                          #30

                          Pete O'Hanlon wrote:

                          a) your understanding is wrong

                          I vote for that! :)

                          xacc.ide - now with TabsToSpaces support
                          IronScheme - 1.0 alpha 4a out now (29 May 2008)

                          1 Reply Last reply
                          0
                          Reply
                          • Reply as topic
                          Log in to reply
                          • Oldest to Newest
                          • Newest to Oldest
                          • Most Votes


                          • Login

                          • Don't have an account? Register

                          • Login or register to search.
                          • First post
                            Last post
                          0
                          • Categories
                          • Recent
                          • Tags
                          • Popular
                          • World
                          • Users
                          • Groups