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. how can i write functions in String class without using any tools?

how can i write functions in String class without using any tools?

Scheduled Pinned Locked Moved C#
questioncsharptoolshelp
36 Posts 10 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

    excuse me, but i haven't to use indexes, too.

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

    So - are you meant to use telepathy? Your professor has effectively ruled out all useful constructs.

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

    My blog | My articles

    C 1 Reply Last reply
    0
    • P Paul Conrad

      Is there a reason why you are wanting to reinvent the wheel?

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

      Yeah, it's homework. I don't have a problem with trying to point him in the right direction, he was up front about it and he's not asking for a solution. It sounds messy tho.

      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
      • D Dave Kreskowiak

        Cute. Considering that String IS a class under .NET, that kind of makes the assignment contradictory to itself, now doesn't it?

        A guide to posting questions on CodeProject[^]
        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
             2006, 2007, 2008

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

        I think either the teacher is an idiot, or the OP is wrong in his understanding

        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 D 2 Replies Last reply
        0
        • S Sajjad Izadi

          no but it's my homework :) and i have to write that till next two days!

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

          Sajjad Izadi wrote:

          have to write that till next two days

          Better get going then.

          "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
          • C Christian Graus

            Yeah, it's homework. I don't have a problem with trying to point him in the right direction, he was up front about it and he's not asking for a solution. It sounds messy tho.

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

            Christian Graus wrote:

            It sounds messy tho.

            Gearing him up for real world maintenance projects, I suppose.

            "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 L 2 Replies Last reply
            0
            • C Christian Graus

              I think either the teacher is an idiot, or the OP is wrong in his understanding

              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

              Christian Graus wrote:

              the teacher is an idiot

              Might be a safe bet. I don't even subject my CS students to worthless crap assignments. Assignments I push on them have some real meaning to them.

              "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
              • P Paul Conrad

                Sajjad Izadi wrote:

                have to write that till next two days

                Better get going then.

                "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
                #21

                I think you need to re-read the assignment. You seem to be saying 'turn a string into a byte array without using any methods on the string class that would give you access to the contents of the string'.

                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
                • P Paul Conrad

                  Christian Graus wrote:

                  It sounds messy tho.

                  Gearing him up for real world maintenance projects, I suppose.

                  "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
                  #22

                  *grin*

                  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
                  • P Paul Conrad

                    Christian Graus wrote:

                    the teacher is an idiot

                    Might be a safe bet. I don't even subject my CS students to worthless crap assignments. Assignments I push on them have some real meaning to them.

                    "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
                    #23

                    Yeah, they should be learning things they can use, although I am always for students writing a list class that they will never use, for example.

                    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

                      I think you need to re-read the assignment. You seem to be saying 'turn a string into a byte array without using any methods on the string class that would give you access to the contents of the string'.

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

                      Didn't you mean to direct this to Sajjad? I'm not the one doing the assignment :-\

                      "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
                      • P Pete OHanlon

                        So - are you meant to use telepathy? Your professor has effectively ruled out all useful constructs.

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

                        I usually suggest prayer when people ask stuff like this.

                        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

                          Yeah, they should be learning things they can use, although I am always for students writing a list class that they will never use, for example.

                          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:

                          always for students writing a list class that they will never use

                          Sure, it primes them up for writing code that never gets used because boss says otherwise, and writing something like a list class teaches the fundamentals of OOP.

                          Christian Graus wrote:

                          they should be learning things they can use

                          Exactly, since they will walk out of the classroom with, hopefully sharper skillsets that can be of value to them. I've had students in the past, who earned lower than average grades thank me for increasing their skillsets, though their academic grade doesn't necessarily reflect it.

                          "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

                            no but it's my homework :) and i have to write that till next two days!

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

                            I think you need to re-read the assignment. You seem to be saying 'turn a string into a byte array without using any methods on the string class that would give you access to the contents of the string'.

                            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
                            • P Paul Conrad

                              Didn't you mean to direct this to Sajjad? I'm not the one doing the assignment :-\

                              "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
                              #28

                              Oh, I hate it when people do 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

                                Oh, I hate it when people do 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
                                #29

                                Oh well, no worries :-D

                                "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

                                  Christian Graus wrote:

                                  It sounds messy tho.

                                  Gearing him up for real world maintenance projects, I suppose.

                                  "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

                                  L Offline
                                  L Offline
                                  Lost User
                                  wrote on last edited by
                                  #30

                                  :laugh:

                                  P 1 Reply Last reply
                                  0
                                  • L Lost User

                                    :laugh:

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

                                    I'll admit I have some code that is a maintenance nightmare, considered "job security" to a certain extent :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

                                    1 Reply Last reply
                                    0
                                    • S Sajjad Izadi

                                      how can i make my string to char[] without using any built-in classes or prepared methods, += and = or 'foreach' in C#? in an other expression, i want to (have to) write trim, insert, concat, countOf(char c) and etc without using any of methods or classes or foreach and even += or + in C#. how is that? please help, thanks.

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

                                      Without using the built in members of the String class, you can't access it's data.

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

                                      P 1 Reply Last reply
                                      0
                                      • C Christian Graus

                                        I think either the teacher is an idiot, or the OP is wrong in his understanding

                                        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.

                                        D Offline
                                        D Offline
                                        Dave Kreskowiak
                                        wrote on last edited by
                                        #33

                                        Why does it have to be "or"?? Why not "and"?? ;)

                                        A guide to posting questions on CodeProject[^]
                                        Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
                                             2006, 2007, 2008

                                        1 Reply Last reply
                                        0
                                        • G Guffa

                                          Without using the built in members of the String class, you can't access it's data.

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

                                          P Offline
                                          P Offline
                                          PIEBALDconsult
                                          wrote on last edited by
                                          #34

                                          I was just wondering whether or not you can with unsafe code... could be fun... :suss: Howsabout this :-D :

                                          private unsafe static void
                                          F
                                          (
                                          string S
                                          ,
                                          out char[] A
                                          )
                                          {
                                          int index = 0 ;

                                          fixed ( char\* s = S )
                                          {
                                              while ( s \[ index \] != '\\0' )
                                              {
                                                  index++ ;
                                              }
                                          
                                              A = new char \[ index \] ;
                                          
                                              fixed ( char\* a = A )
                                              {
                                                  while ( index >= 0 )
                                                  {
                                                      a \[ index \] = s \[ index \] ;
                                          
                                                      index-- ;
                                                  }
                                              }
                                          }
                                          
                                          return ;
                                          

                                          }

                                          Or lambda expressions?

                                          modified on Monday, July 7, 2008 11:47 PM

                                          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