reverse syntax

Is there a syntax that reverses things?
Example: 123 int 321

Comments

  • : Is there a syntax that reverses things?
    : Example: 123 int 321
    :



    Hi!
    I'll give u the C code. U change it to VB.


    void main()
    {
    int n = 12345,rev = 0,num = 0;
    while(n>0)
    {
    num = n % 10;
    rev = rev*10 + num;
    n = n/10;
    }
    printf("%d",rev);

    }

    U can pass any value instead of "n"



  • [b][red]This message was edited by lionb at 2005-12-8 13:11:31[/red][/b][hr]
    : Is there a syntax that reverses things?
    : Example: 123 int 321
    :
    There is always some syntax around ... if you willing to think a little bit ;-)
    [code]
    Private Sub Command1_Click()
    Dim i As Integer
    Dim sOld As String, sReverse As String

    sOld = "123"

    For i = Len(sOld) To 0 Step -1
    If i > 0 Then
    sReverse = sReverse & Mid(sOld, i, 1)
    End If
    Next
    Text1 = sReverse
    End Sub
    [/code]


  • : [b][red]This message was edited by lionb at 2005-12-8 13:11:31[/red][/b][hr]
    : : Is there a syntax that reverses things?
    : : Example: 123 int 321
    : :
    : There is always some syntax around ... if you willing to think a little bit ;-)
    : [code]
    : Private Sub Command1_Click()
    : Dim i As Integer
    : Dim sOld As String, sReverse As String
    :
    : sOld = "123"
    :
    : For i = Len(sOld) To 0 Step -1
    : If i > 0 Then
    : sReverse = sReverse & Mid(sOld, i, 1)
    : End If
    : Next
    : Text1 = sReverse
    : End Sub
    : [/code]
    :
    :
    :

    This one works much faster:
    [Code]
    Private Function Mod_sReverse(ByRef sOriginal As String) As String

    Dim lIndex As Long
    Dim lLen As Long
    Dim sReverse As String

    lLen = Len(sOriginal)
    '''Preallocate string
    sReverse = sOriginal
    For lIndex = 1 To lLen
    '''move each character
    Mid$(sReverse, (lLen - lIndex + 1), 1) = Mid(sOriginal, lIndex, 1)
    Next lIndex
    Mod_sReverse = sReverse
    End Function
    [/Code]
    Mike
  • How faster?
  • : How faster?
    :

    Like

    [code]
    Dim sString As String
    Dim sReverse As String

    sString = "123"
    sReverse = StrReverse(sString)
    [/code]

    Much faster... Or atleast for VB6 and VB.NET

    Best Regards,
    Richard

  • : : How faster?
    : :
    :
    : Like
    :
    : [code]
    : Dim sString As String
    : Dim sReverse As String
    :
    : sString = "123"
    : sReverse = StrReverse(sString)
    : [/code]
    :
    : Much faster... Or atleast for VB6 and VB.NET
    :
    : Best Regards,
    : Richard
    :
    Thanks! I did know that StrReverse() was existed in vb6. Learn every day!
  • Thanks I thought there was something like Thor wrote but I wasn't for sure.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories