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

    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.

    L C P D G 7 Replies 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.

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

      Sajjad Izadi wrote:

      how can i make my string to char[] without using any built-in classes or prepared methods, += and = or 'foreach' in C#?

      "foo".ToCharArray()

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

      H S 2 Replies Last reply
      0
      • L leppie

        Sajjad Izadi wrote:

        how can i make my string to char[] without using any built-in classes or prepared methods, += and = or 'foreach' in C#?

        "foo".ToCharArray()

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

        H Offline
        H Offline
        hammerstein05
        wrote on last edited by
        #3

        Is that not a built-in class or prepared method? Forgive me, but this does sound like a school assignment.

        S 1 Reply Last reply
        0
        • L leppie

          Sajjad Izadi wrote:

          how can i make my string to char[] without using any built-in classes or prepared methods, += and = or 'foreach' in C#?

          "foo".ToCharArray()

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

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

          excuse me, but as i said, i haven't too use any prepared method for that.

          H L 2 Replies Last reply
          0
          • S Sajjad Izadi

            excuse me, but as i said, i haven't too use any prepared method for that.

            H Offline
            H Offline
            hammerstein05
            wrote on last edited by
            #5

            Is this a school assignment?

            1 Reply Last reply
            0
            • H hammerstein05

              Is that not a built-in class or prepared method? Forgive me, but this does sound like a school assignment.

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

              yes, our professor is wanted us to write a program like that and he told us that we can get help from everyone we want. and i'm getting help from you :).

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

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

                I don't see how you can do it without =, but a string is an array of chars, and if you use a for loop instead of foreach, you can get each char by index, as in myString[0]

                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
                • S Sajjad Izadi

                  yes, our professor is wanted us to write a program like that and he told us that we can get help from everyone we want. and i'm getting help from you :).

                  H Offline
                  H Offline
                  hammerstein05
                  wrote on last edited by
                  #8

                  You'll need to do some coding of your own, and then ask for specific help when you get stuck. You can't just come in here and ask for the code. that's not how it works. The forums aren't for you to get your solution done for you. And you'll find that in most of the forums available.

                  1 Reply Last reply
                  0
                  • S Sajjad Izadi

                    excuse me, but as i said, i haven't too use any prepared method for that.

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

                    If you cant use any methods on it, then the string is opaque to you, and there is no way you can do anything with it. I think you read your assignment wrong. Try again.

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

                    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.

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

                      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

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

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

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

                          I don't see how you can do it without =, but a string is an array of chars, and if you use a for loop instead of foreach, you can get each char by index, as in myString[0]

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

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

                          C P 2 Replies Last reply
                          0
                          • S Sajjad Izadi

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

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

                            Then I suspect your teacher is a moron. An index is the only way to get those chars out 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

                              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

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

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

                              P C 2 Replies Last reply
                              0
                              • 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
                                        • 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
                                          #20

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