Hi,
How can i Inverse a text?
"abcdefgh" to "hgfedcba"
Regards
Printable View
Hi,
How can i Inverse a text?
"abcdefgh" to "hgfedcba"
Regards
If you have VB6, use the strReverse function.
If not, you can make your own.Code:Text1 = StrReverse(Text1)
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
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
Do you mean Windows as in Notepad and DOS as in Edit? If so, they are both ASCII format therefor, it should work.
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?
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]
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
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")
Thanks to ALL OF U.
This is what i was looking for.
Thanks again.