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. Other Discussions
  3. The Back Room
  4. How to reverse a string

How to reverse a string

Scheduled Pinned Locked Moved The Back Room
tutorial
9 Posts 7 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.
  • G Offline
    G Offline
    Gabriel P G
    wrote on last edited by
    #1

    In the eighties, the "dude, OO is soooo easy" decade string s2 = reverse(s1); In the nineties, the "dude, this cannot be THIS easy" decade string s2 = s1.Clone(); s2.Reverse(); In the current, "best practices and patterns" decade StringClonator clonator = new StringClonator(); string s2 = clonator.Clone(s1); StringIterator begin = s2.Begin(); StringIterator end = s2.End(); StringBuffer buffer = new StringBuffer(s2.size()); ReversingStrategy reverser = ReversingStrategyFactory.GetInstance.NewReversingStrategy(); reverser.Reverse(s2, begin, end, buffer); s2.AssignBuffer(buffer.InnerBuffer());

    C B S S M 6 Replies Last reply
    0
    • G Gabriel P G

      In the eighties, the "dude, OO is soooo easy" decade string s2 = reverse(s1); In the nineties, the "dude, this cannot be THIS easy" decade string s2 = s1.Clone(); s2.Reverse(); In the current, "best practices and patterns" decade StringClonator clonator = new StringClonator(); string s2 = clonator.Clone(s1); StringIterator begin = s2.Begin(); StringIterator end = s2.End(); StringBuffer buffer = new StringBuffer(s2.size()); ReversingStrategy reverser = ReversingStrategyFactory.GetInstance.NewReversingStrategy(); reverser.Reverse(s2, begin, end, buffer); s2.AssignBuffer(buffer.InnerBuffer());

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

      ROTFL !!! Is this Java ?

      Christian Graus Driven to the arms of OSX by Vista. "Iam doing the browsing center project in vb.net using c# coding" - this is why I don't answer questions much anymore. Oh, and Microsoft doesn't want me to.

      1 Reply Last reply
      0
      • G Gabriel P G

        In the eighties, the "dude, OO is soooo easy" decade string s2 = reverse(s1); In the nineties, the "dude, this cannot be THIS easy" decade string s2 = s1.Clone(); s2.Reverse(); In the current, "best practices and patterns" decade StringClonator clonator = new StringClonator(); string s2 = clonator.Clone(s1); StringIterator begin = s2.Begin(); StringIterator end = s2.End(); StringBuffer buffer = new StringBuffer(s2.size()); ReversingStrategy reverser = ReversingStrategyFactory.GetInstance.NewReversingStrategy(); reverser.Reverse(s2, begin, end, buffer); s2.AssignBuffer(buffer.InnerBuffer());

        B Offline
        B Offline
        blackjack2150
        wrote on last edited by
        #3

        interface Printer {
        void print(Message message);
        }

        class Message {
        private String message;

        public Message(String message) {
            this.message = message;
        }
        
        public void print(Printer printer) {
            printer.print(this);
        }
        
        public String toString() {
            return message;
        }
        

        }

        abstract class AbstractPrinterFactory {
        public static AbstractPrinterFactory getFactory() {
        return new SystemOutPrinterFactory();
        }

        public abstract Printer getPrinter();
        

        }

        class SystemOutPrinterFactory extends AbstractPrinterFactory {
        public Printer getPrinter() {
        return new SystemOutPrinter();
        }
        }

        class SystemOutPrinter implements Printer {
        public void print(Message message) {
        System.out.println(message);
        }
        }

        class HelloWorld {
        public static void main(String[] args) {
        Message message = new Message("Hello, World!");
        AbstractPrinterFactory factory = AbstractPrinterFactory.getFactory();
        Printer printer = factory.getPrinter();
        message.print(printer);
        }
        }

        1 Reply Last reply
        0
        • G Gabriel P G

          In the eighties, the "dude, OO is soooo easy" decade string s2 = reverse(s1); In the nineties, the "dude, this cannot be THIS easy" decade string s2 = s1.Clone(); s2.Reverse(); In the current, "best practices and patterns" decade StringClonator clonator = new StringClonator(); string s2 = clonator.Clone(s1); StringIterator begin = s2.Begin(); StringIterator end = s2.End(); StringBuffer buffer = new StringBuffer(s2.size()); ReversingStrategy reverser = ReversingStrategyFactory.GetInstance.NewReversingStrategy(); reverser.Reverse(s2, begin, end, buffer); s2.AssignBuffer(buffer.InnerBuffer());

          S Offline
          S Offline
          Sathesh Sakthivel
          wrote on last edited by
          #4

          LMAO.

          Sathesh. Blessed is the season which engages the whole world in a conspiracy of love.

          1 Reply Last reply
          0
          • G Gabriel P G

            In the eighties, the "dude, OO is soooo easy" decade string s2 = reverse(s1); In the nineties, the "dude, this cannot be THIS easy" decade string s2 = s1.Clone(); s2.Reverse(); In the current, "best practices and patterns" decade StringClonator clonator = new StringClonator(); string s2 = clonator.Clone(s1); StringIterator begin = s2.Begin(); StringIterator end = s2.End(); StringBuffer buffer = new StringBuffer(s2.size()); ReversingStrategy reverser = ReversingStrategyFactory.GetInstance.NewReversingStrategy(); reverser.Reverse(s2, begin, end, buffer); s2.AssignBuffer(buffer.InnerBuffer());

            S Offline
            S Offline
            Simon P Stevens
            wrote on last edited by
            #5

            :laugh: :laugh: Very funny. Have you seen this rant about frameworks[^]. It's a similar thing. Old, but funny.

            Simon

            1 Reply Last reply
            0
            • G Gabriel P G

              In the eighties, the "dude, OO is soooo easy" decade string s2 = reverse(s1); In the nineties, the "dude, this cannot be THIS easy" decade string s2 = s1.Clone(); s2.Reverse(); In the current, "best practices and patterns" decade StringClonator clonator = new StringClonator(); string s2 = clonator.Clone(s1); StringIterator begin = s2.Begin(); StringIterator end = s2.End(); StringBuffer buffer = new StringBuffer(s2.size()); ReversingStrategy reverser = ReversingStrategyFactory.GetInstance.NewReversingStrategy(); reverser.Reverse(s2, begin, end, buffer); s2.AssignBuffer(buffer.InnerBuffer());

              M Offline
              M Offline
              MrPlankton
              wrote on last edited by
              #6

              :) I suspect if you include the unit tests, it could be even more verbose.

              MrPlankton

              (bad guy)"Fear is a hammer, and when the people are beaten finally to the conviction that their existence hangs by a frayed thread, they will be led where they need to go."

              (good guy)"Which is where?"

              (bad guy)"To a responsible future in a properly managed world."
              Dean Koontz, The Good Guy

              1 Reply Last reply
              0
              • G Gabriel P G

                In the eighties, the "dude, OO is soooo easy" decade string s2 = reverse(s1); In the nineties, the "dude, this cannot be THIS easy" decade string s2 = s1.Clone(); s2.Reverse(); In the current, "best practices and patterns" decade StringClonator clonator = new StringClonator(); string s2 = clonator.Clone(s1); StringIterator begin = s2.Begin(); StringIterator end = s2.End(); StringBuffer buffer = new StringBuffer(s2.size()); ReversingStrategy reverser = ReversingStrategyFactory.GetInstance.NewReversingStrategy(); reverser.Reverse(s2, begin, end, buffer); s2.AssignBuffer(buffer.InnerBuffer());

                S Offline
                S Offline
                shiftedbitmonkey
                wrote on last edited by
                #7

                How about the "Dude, I can do that in one line of supported illegal C" #define swap(x, y) x^= y^= x^=y

                I've heard more said about less.

                G 1 Reply Last reply
                0
                • S shiftedbitmonkey

                  How about the "Dude, I can do that in one line of supported illegal C" #define swap(x, y) x^= y^= x^=y

                  I've heard more said about less.

                  G Offline
                  G Offline
                  Gabriel P G
                  wrote on last edited by
                  #8

                  nope, your sample is "1337 codez", my sample is "enterprise-ready code"

                  S 1 Reply Last reply
                  0
                  • G Gabriel P G

                    nope, your sample is "1337 codez", my sample is "enterprise-ready code"

                    S Offline
                    S Offline
                    shiftedbitmonkey
                    wrote on last edited by
                    #9

                    Oh yeah. Did you work in the enterprise in the late 80s early 90s? I saw this swap everywhere and had to actually prove to a guy that it is in fact illegal in C++. Can't assign twice to a variable between two sequence points. Definitely in the enterprise.

                    I've heard more said about less.

                    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