Hi,

I have a done the following steps which can help you understanding my problem:

1. I took a decimal point number, suppose 192.123456

2. Then removed the decimal point

3. Concatenated the L.H.S and R.H.S and stored it in a string

4. The string that I got was 192132456

Problem:

1. Now I want that the I should be able to reverse the string such that the string should become 5624132901.

Can anyone help in this matter and tell me how is it possible!!!

I have tried using the arrays but it gives me an error when I try storing a string into an array.

Any help will be very much appreciated.

I am pasting the code below:

NOTE: Code does not contain the implementation of arrays as discussed above. The logic below is without arrays.

Dim maindecimal_R_Reverse_Parts As String = ""
        Dim mainbandnumber_R = CStr(MainBandText.Text)
        Dim mainpos_R = InStr(mainbandnumber_R, ".")
        Dim maindecimals_R = Microsoft.VisualBasic.Right(mainbandnumber_R, Len(mainbandnumber_R) - mainpos_R)

        'Determining the length of the maindecimal_R
        Dim maindecimals_R_length = Len(maindecimals_R)

        'Reverse the maindecimals_R
        Dim maincount_R = 0

        Dim maindecimals_R_Reverse = ""


        For n = 0 To maindecimals_R_length - 1
            maindecimals_R_Reverse = Mid(maindecimals_R, maindecimals_R_length - n, 2)

            If Not n \ 2 = 0 Or n = 1 Then

                maindecimal_R_Reverse_Parts = maindecimal_R_Reverse_Parts & maindecimals_R_Reverse
            End If


        Next n

Regards,

Bilal A. Khan

As far as I can see, is not a simple reverse, you are reversing the string in pairs so the code is not so straightforward.

When the string is odd, the code is adding a non existent 0 in the original string.
I came with this code, I hope this is what you need.

Private Function Encode(ByVal input As String) As String
        Dim tmp As String = String.Empty
        For i = input.Length - 2 To 0 Step -2
                tmp &= input.Substring(i, 2)
        Next
        If input.Length Mod 2 = 1 Then
            tmp &= "0" & input.Substring(0, 1)
        End If
        Return tmp
    End Function

    Private Function Decode(ByVal input As String) As String
        Dim tmp As String = String.Empty
        For i = input.Length - 2 To 0 Step -2
            tmp &= input.Substring(i, 2)
        Next
        If tmp.Substring(0, 1) = "0" Then
            tmp = tmp.Substring(1)
        End If
        Return tmp
    End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.