Results 1 to 9 of 9

Thread: Text Inverse

  1. #1

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Hi,
    How can i Inverse a text?
    "abcdefgh" to "hgfedcba"

    Regards

  2. #2
    Guest
    If you have VB6, use the strReverse function.

    Code:
    Text1 = StrReverse(Text1)
    If not, you can make your own.

    Code:
    Private Function StrReverse(ByVal sIn As String) As String
        Dim nC As Integer, sOut As String
        For nC = Len(sIn) To 1 Step -1
        sOut = sOut & Mid(sIn, nC, 1)
        Next
        StrReverse = sOut
    End Function
    
    Private Sub Command1_Click()
    
        Text1 = StrReverse(Text1)
    
    End Sub

  3. #3

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Megatron,
    1ST - Thanks
    2ND - I try to convert a text file from WINDOWS format to DOS format, the output text is still not good. any idea?
    (the convert is good BUT the direction is NOT).

    Regards

  4. #4
    Guest
    Do you mean Windows as in Notepad and DOS as in Edit? If so, they are both ASCII format therefor, it should work.

  5. #5

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Megatron,
    You r right - i think i was wrong - what i need is that, I have a file or text for the sample,
    "fedcba" and i like to change is to
    "abcdef"

    Can i do it?

  6. #6
    Guest
    Backwards?

    Code:
    Private Function backwards(strin As String)
    Let inptxt$ = strin
    Let lenth% = Len(inptxt$)
    Do While numspc% <= lenth%
    Let numspc% = numspc% + 1
    Let nextChr$ = Mid$(inptxt$, numspc%, 1)
    Let newsent$ = nextChr$ & newsent$
    Loop
    backwards = newsent$
    End Function
    
    t = backwards("fedcba")
    MsgBox t 'returns abcdef

    [Edited by Matthew Gates on 07-31-2000 at 12:51 AM]

  7. #7
    Guest
    All you really need is this line. strTemp = StrReverse(strTemp). The rest just is a matter of opening and saving the file.

    Code:
    'Get the Text from the file
    Open "C:\MyFile.txt" For Input As #1
    strTemp = Input(LOF(1), 1)
    Close #1
    
    'Reverse the text from the file
    strTemp = StrReverse(strTemp)
    
    'Save the File
    Open "C:\MyFile.txt" For Output As #1
    Print #1, strTemp
    Close #1

  8. #8
    Guest
    Or you could always use this code to reverse a file .

    Code:
    Function Code
    Public Sub reversefile(fromfile _
    As String, tofile As String)
    ' Fromfile: file to get data from
    ' Tofile: file to put data in
    ' Note: This does not work very 
    ' well on strings as it does not seem to
    ' recognise new lines.
    
    Dim mybyte() As Byte
    Dim reversedbyte() As Byte
    Dim reversebyte As Long
    
    Open fromfile For Binary As #1
    Open tofile For Binary As #2
    
    ReDim mybyte(1 To LOF(1)) As Byte
    ReDim reversedbyte(1 To LOF(1)) As Byte
    Get #1, , mybyte
    
    For reversebyte = UBound(mybyte) To 1 Step -1
    reversedbyte(reversebyte) = mybyte(UBound(mybyte) - _
    reversebyte + 1)
    Next
    
    Put #2, , reversedbyte
    
    Close #2
    Close #1
    
    End Sub
    
    Usage:
    call reversefile("c:\fromfile.dat","c:\tofile.dat")

  9. #9

    Thread Starter
    Addicted Member Tiovital's Avatar
    Join Date
    Apr 2000
    Posts
    249
    Thanks to ALL OF U.
    This is what i was looking for.

    Thanks again.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width