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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. reverse a string

reverse a string

Scheduled Pinned Locked Moved C#
tutorial
5 Posts 5 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.
  • D Offline
    D Offline
    divya simma
    wrote on last edited by
    #1

    how to reverse a string

    N M C M 4 Replies Last reply
    0
    • D divya simma

      how to reverse a string

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Please read the point 9 here[^]

      Navaneeth How to use google | Ask smart questions

      1 Reply Last reply
      0
      • D divya simma

        how to reverse a string

        M Offline
        M Offline
        Mirko1980
        wrote on last edited by
        #3

        If you are using .NET 3.5, you can do string reversedString = new string(originalString.ToCharArray().Reverse().ToArray());. Otherwise, just use a for loop and do it manually. Edit - this works in .NET 2.0 too:

        List charList = new List(originalString);
        charList.Reverse();
        string reversedString = new string(charList.ToArray());

        1 Reply Last reply
        0
        • D divya simma

          how to reverse a string

          C Offline
          C Offline
          Cracked Down
          wrote on last edited by
          #4

          There is no such interface provided by the string class we have to do it usind somw work arounds here is one sulution 1. Convert the string to character array 2. Array provides interface to reverse its element 3. you got ur string in reverse order :) :) :)

          1 Reply Last reply
          0
          • D divya simma

            how to reverse a string

            M Offline
            M Offline
            musefan
            wrote on last edited by
            #5

            First, put your foot down on the clutch. Second, put it into reverese gear. Third, slightly press down on the accelerator and bring the clutch up till it starts to reverse (aplly more accelartion as needed)... easy :) ...OH, String - sorry i thought you said car... though technically you didnt speak at all... you not still reading are you?... though why am i still talking (i mean writting) complete rubbish?!?!? TGIF :D (On a serious note though (as found hidden between D# and E(well perhaps 90% serious :P)) <- i hate it when that happens lol If you are doing a homework assignment of some sort may i suggest you comment out any code you have taken from the other posts (still keep thou for proof of concept) and write something like as follows - its all about the theory really.

            public string MyReverseFunction(string s)
            {
            string result = "";
            for(int i = s.Length-1; i >= 0; i--)
            result += s[i];
            return result;
            }

            Oh and make a note that it is prob best to use a StringBuilder to help with performance on large strings

            If only MySelf.Visible was more than just a getter... A person can produce over 5 times there own body weight in excrement each year... please re-read your questions before posting

            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