locked
Help with program I want to write. RRS feed

  • Question

  • I want to write a program in which you have to take a name and then reverse it. I can't seem to figure out how to use strings on smallbasic. Thanks Inadvances!

    Ex: What is your name: waffleninja
          Your name backwards is: ajninwlffaw

    Tuesday, January 17, 2012 11:39 PM

Answers

  • It's a standard programming questions during interview for software engineer position.

    With SB, you can parse the name into an array of character then write it from the end.

    Another way, you can try using the Stack. push the character in, then you print out each character when you pop it out of the stack.

    Can you give it a try?

    Wednesday, January 18, 2012 4:03 AM
  • Try this

    public static void ReverseString()
            {
                StringBuilder reversedString=new StringBuilder();
                StringBuilder sb = null;
                var readLine = Console.ReadLine();
                if (readLine != null) sb = new StringBuilder(readLine);
                for (int i = sb.Length-1; i >= 0; i--)
                {
                    reversedString.Append(sb[i]);
                }
    
                Console.WriteLine(reversedString.ToString());
                Console.ReadLine();
            }
    



    Every day its a new learning. Keep Learning!!
    If this post answers your question, please click Mark As Answer . If this post is helpful please click Mark as Helpful
    Wednesday, January 18, 2012 4:35 AM

All replies

  • It's a standard programming questions during interview for software engineer position.

    With SB, you can parse the name into an array of character then write it from the end.

    Another way, you can try using the Stack. push the character in, then you print out each character when you pop it out of the stack.

    Can you give it a try?

    Wednesday, January 18, 2012 4:03 AM
  • Try this

    public static void ReverseString()
            {
                StringBuilder reversedString=new StringBuilder();
                StringBuilder sb = null;
                var readLine = Console.ReadLine();
                if (readLine != null) sb = new StringBuilder(readLine);
                for (int i = sb.Length-1; i >= 0; i--)
                {
                    reversedString.Append(sb[i]);
                }
    
                Console.WriteLine(reversedString.ToString());
                Console.ReadLine();
            }
    



    Every day its a new learning. Keep Learning!!
    If this post answers your question, please click Mark As Answer . If this post is helpful please click Mark as Helpful
    Wednesday, January 18, 2012 4:35 AM
  • Cool thanks. 
    Wednesday, January 18, 2012 8:45 PM