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 Offline
    S Offline
    Sajjad Izadi
    wrote on last edited by
    #1

    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

    S C P P G 5 Replies 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

      S Offline
      S Offline
      SomeGuyThatIsMe
      wrote on last edited by
      #2

      dont use the String class...use the string type...thats what i'd do, i would also call the professor a moron probably in class...which explains my excellent grades in college. and like everyone mentioned before, if you get stuck at some specific place ask here, we will not do you homework for you. most of us didnt have these kind of resources when we took those classes, or didnt use them for anything other than very spcific questions if we did.

      Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

      C 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

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

        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.

        S L 3 Replies Last reply
        0
        • S SomeGuyThatIsMe

          dont use the String class...use the string type...thats what i'd do, i would also call the professor a moron probably in class...which explains my excellent grades in college. and like everyone mentioned before, if you get stuck at some specific place ask here, we will not do you homework for you. most of us didnt have these kind of resources when we took those classes, or didnt use them for anything other than very spcific questions if we did.

          Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

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

          SomeGuyThatIsMe wrote:

          dont use the String class...use the string type...

          How do you thing the 'String class' and the 'string type' differ ? Whatever you think, you're mistaken.

          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.

          S 1 Reply Last reply
          0
          • C Christian Graus

            SomeGuyThatIsMe wrote:

            dont use the String class...use the string type...

            How do you thing the 'String class' and the 'string type' differ ? Whatever you think, you're mistaken.

            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.

            S Offline
            S Offline
            SomeGuyThatIsMe
            wrote on last edited by
            #5

            I assumed it was a trick question, and that they couldnt use the String class, but using string instead would work, since they work the same, his assignment would be easy. and since String is capitalized i assume its a class, and since string isnt and VS changes it color jus tlike other base types(int, double, char, etc..), i call it a type, even though it is a class just to tell them apart. bad behavior, but old habits are hard to break. i realize they arent different aside from that. but if it wasnt a trick question and he cant use a foreach, or indexes, or any member function he's pretty hosed..tho what about Convert? does it have a method to take strings to char[]'s i cant remember.

            Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

            C C 2 Replies 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.

              S Offline
              S Offline
              Sajjad Izadi
              wrote on last edited by
              #6

              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.

              C P 2 Replies Last reply
              0
              • S SomeGuyThatIsMe

                I assumed it was a trick question, and that they couldnt use the String class, but using string instead would work, since they work the same, his assignment would be easy. and since String is capitalized i assume its a class, and since string isnt and VS changes it color jus tlike other base types(int, double, char, etc..), i call it a type, even though it is a class just to tell them apart. bad behavior, but old habits are hard to break. i realize they arent different aside from that. but if it wasnt a trick question and he cant use a foreach, or indexes, or any member function he's pretty hosed..tho what about Convert? does it have a method to take strings to char[]'s i cant remember.

                Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

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

                He could just use [] to access the chars and build whatever he likes. String and string are the same thing. They are not two objects that look the same, they are the same object.

                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.

                1 Reply Last reply
                0
                • 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.

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

                  Sajjad Izadi wrote:

                  thanks for your answer but 'foreach' and indexes are not allowed to use, too.

                  you keep saying that, but: 1 - the question does NOT say that 2 - that means there is no solution. Except maybe prayer or voodoo magic.

                  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.

                  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
                    #9

                    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|


                    C P G 3 Replies 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|


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

                      Hmmm - I didn't think of that. I guess I was looking for educational value, I assumed he wanted them to learn about how to use array indexes. Plus, he's insisting he can't use stuff that the question doesn't say. What a *dumb* thing for a teacher to assign, if the answer is to use a stringbuilder. But, wait, how would they get substrings, etc ? I mean, they would then need to call methods on the string class, via the string returned from ToString, right ? I reviewed the assignment, and while there's no substring, there is a reverse, and other methods such as finding the index of a string in another, that make me think that a stringbuilder is definately not the answer being sought, and that addressing chars in a string by index, is.

                      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 1 Reply Last reply
                      0
                      • C Christian Graus

                        Hmmm - I didn't think of that. I guess I was looking for educational value, I assumed he wanted them to learn about how to use array indexes. Plus, he's insisting he can't use stuff that the question doesn't say. What a *dumb* thing for a teacher to assign, if the answer is to use a stringbuilder. But, wait, how would they get substrings, etc ? I mean, they would then need to call methods on the string class, via the string returned from ToString, right ? I reviewed the assignment, and while there's no substring, there is a reverse, and other methods such as finding the index of a string in another, that make me think that a stringbuilder is definately not the answer being sought, and that addressing chars in a string by index, is.

                        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
                        #11

                        No string operations are required at all once the raw data is available, and that is what new StringBuilder(string) does. So basically it is used as a replacement for the index operator, allowing an almost native implementation of string functions. I do agree it isn't a very smart assignment. :)

                        Luc Pattyn [Forum Guidelines] [My Articles]


                        Voting for dummies? No thanks. X|


                        C 1 Reply Last reply
                        0
                        • S SomeGuyThatIsMe

                          I assumed it was a trick question, and that they couldnt use the String class, but using string instead would work, since they work the same, his assignment would be easy. and since String is capitalized i assume its a class, and since string isnt and VS changes it color jus tlike other base types(int, double, char, etc..), i call it a type, even though it is a class just to tell them apart. bad behavior, but old habits are hard to break. i realize they arent different aside from that. but if it wasnt a trick question and he cant use a foreach, or indexes, or any member function he's pretty hosed..tho what about Convert? does it have a method to take strings to char[]'s i cant remember.

                          Please remember to rate helpful or unhelpful answers, it lets us and people reading the forums know if our answers are any good.

                          C Offline
                          C Offline
                          Colin Angus Mackay
                          wrote on last edited by
                          #12

                          SomeGuyThatIsMe wrote:

                          since they work the same

                          They don't work the same. The ARE the same! string is a synonym for System.String

                          SomeGuyThatIsMe wrote:

                          since String is capitalized i assume its a class

                          And a class is a type.

                          Recent blog posts: * Event Organisation (Feedback) * LINQ to XML (part 4) * Scottish Developers June Newsletter My Blog

                          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

                            P Offline
                            P Offline
                            Pete OHanlon
                            wrote on last edited by
                            #13

                            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

                            C P L 3 Replies Last reply
                            0
                            • L Luc Pattyn

                              No string operations are required at all once the raw data is available, and that is what new StringBuilder(string) does. So basically it is used as a replacement for the index operator, allowing an almost native implementation of string functions. I do agree it isn't a very smart assignment. :)

                              Luc Pattyn [Forum Guidelines] [My Articles]


                              Voting for dummies? No thanks. X|


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

                              You're saying there's a tostring on StringBuilder that takes indexes for substrings ? That DOES make sense of not being allowed to use +, you don't need to. How odd...

                              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 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

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

                                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 1 Reply Last reply
                                0
                                • C Christian Graus

                                  You're saying there's a tostring on StringBuilder that takes indexes for substrings ? That DOES make sense of not being allowed to use +, you don't need to. How odd...

                                  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
                                  #16

                                  Christian Graus wrote:

                                  You're saying there's a tostring on StringBuilder that takes indexes for substrings ?

                                  I did not intend to say that, but yes it does exist. Anyway one does not need it, access to the raw data plus some character moving is all it takes. Import with the SB constructor, export with a simple SB.ToString. :)

                                  Luc Pattyn [Forum Guidelines] [My Articles]


                                  Voting for dummies? No thanks. X|


                                  C 1 Reply Last reply
                                  0
                                  • L Luc Pattyn

                                    Christian Graus wrote:

                                    You're saying there's a tostring on StringBuilder that takes indexes for substrings ?

                                    I did not intend to say that, but yes it does exist. Anyway one does not need it, access to the raw data plus some character moving is all it takes. Import with the SB constructor, export with a simple SB.ToString. :)

                                    Luc Pattyn [Forum Guidelines] [My Articles]


                                    Voting for dummies? No thanks. X|


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

                                    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 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

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

                                      You don't need to post again if the other thread is getting long.

                                      "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
                                      • 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
                                          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