10 Replies - 5573 Views - Last Post: 05 March 2010 - 07:17 AM Rate Topic: -----

#1 jkeilman  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 04-March 10

Reversing a string without using .reverse?

Posted 04 March 2010 - 10:27 PM

I have a project at my school and I have to reverse a string without using .Reverse... how would I go about doing this?

for instance, Bear would become "Raeb," function would become "noitcnuf"
Is This A Good Question/Topic? 0
  • +

Replies To: Reversing a string without using .reverse?

#2 gregoryH  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 60
  • View blog
  • Posts: 656
  • Joined: 04-October 06

Re: Reversing a string without using .reverse?

Posted 04 March 2010 - 11:02 PM

mmm most interesting, may I inquire what you have researched or thought that you might be able to use?
Was This Post Helpful? 0
  • +
  • -

#3 jkeilman  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 15
  • Joined: 04-March 10

Re: Reversing a string without using .reverse?

Posted 04 March 2010 - 11:36 PM

I have seen suggestions to use indexof... but I don't know how that would really help me
Was This Post Helpful? 0
  • +
  • -

#4 Searock  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 35
  • View blog
  • Posts: 259
  • Joined: 15-September 09

Re: Reversing a string without using .reverse?

Posted 05 March 2010 - 12:33 AM

Well if you use Google you will get a ready code over there.

I will explain you the logic

You will have to use the mid function along with a loop to extract characters from the end.

Try to code and if you get stuck let me know, I will be glad to help you.

This post has been edited by Searock: 05 March 2010 - 12:36 AM

Was This Post Helpful? 0
  • +
  • -

#5 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Reversing a string without using .reverse?

Posted 05 March 2010 - 04:10 AM

IndexOf will give you the position of a known character or string inside a string
Mid is legacy code and will not work without the VisualBasic namespace

Look up string.chars(). It's what you will want to use. Put it in a loop that steps in reverse and append each result in the new string.
Was This Post Helpful? 0
  • +
  • -

#6 clboyrun  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 14
  • Joined: 19-January 10

Re: Reversing a string without using .reverse?

Posted 05 March 2010 - 05:03 AM

InStrRev(String) always worked for me
Was This Post Helpful? 0
  • +
  • -

#7 CharlieMay  Icon User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1605
  • View blog
  • Posts: 5,162
  • Joined: 25-September 09

Re: Reversing a string without using .reverse?

Posted 05 March 2010 - 05:25 AM

View Postclboyrun, on 05 March 2010 - 06:03 AM, said:

InStrRev(String) always worked for me


InStrRev finds the occurrence of a string inside a string starting from the right side (end) of the string as apposed to InStr which does the same thing starting from the left side of the string.

Unless there is a method of using this that I haven't seen, I don't think that functions the way you're thinking. Otherwise, I would like to see the code you use to reverse a string with it :)

This post has been edited by CharlieMay: 05 March 2010 - 05:27 AM

Was This Post Helpful? 0
  • +
  • -

#8 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Reversing a string without using .reverse?

Posted 05 March 2010 - 05:34 AM

Count backwords.
Was This Post Helpful? 0
  • +
  • -

#9 clboyrun  Icon User is offline

  • New D.I.C Head

Reputation: -4
  • View blog
  • Posts: 14
  • Joined: 19-January 10

Re: Reversing a string without using .reverse?

Posted 05 March 2010 - 06:01 AM

dim strNormal as string = "Bear"
dim strReverse as string = InStrRev(strNormal)


This should work for you.
Was This Post Helpful? -2
  • +
  • -

#10 T3hC13h  Icon User is offline

  • D.I.C Regular

Reputation: 65
  • View blog
  • Posts: 337
  • Joined: 05-February 08

Re: Reversing a string without using .reverse?

Posted 05 March 2010 - 07:12 AM

View Postclboyrun, on 05 March 2010 - 07:01 AM, said:

dim strNormal as string = "Bear"
dim strReverse as string = InStrRev(strNormal)


This should work for you.



I think the point of the exercise is to NOT use built-in string reverse functions.
Was This Post Helpful? 0
  • +
  • -

#11 raziel_  Icon User is offline

  • Like a lollipop
  • member icon

Reputation: 464
  • View blog
  • Posts: 4,255
  • Joined: 25-March 09

Re: Reversing a string without using .reverse?

Posted 05 March 2010 - 07:17 AM

use len() and mid()

This post has been edited by NoBrain: 05 March 2010 - 07:18 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1