|
-
Jul 30th, 2000, 07:18 AM
#1
Thread Starter
Addicted Member
Hi,
How can i Inverse a text?
"abcdefgh" to "hgfedcba"
Regards
-
Jul 30th, 2000, 08:10 AM
#2
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
-
Jul 30th, 2000, 08:32 AM
#3
Thread Starter
Addicted Member
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
-
Jul 30th, 2000, 08:42 AM
#4
Do you mean Windows as in Notepad and DOS as in Edit? If so, they are both ASCII format therefor, it should work.
-
Jul 30th, 2000, 11:40 PM
#5
Thread Starter
Addicted Member
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?
-
Jul 30th, 2000, 11:49 PM
#6
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]
-
Jul 31st, 2000, 08:09 AM
#7
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
-
Jul 31st, 2000, 03:08 PM
#8
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")
-
Jul 31st, 2000, 11:32 PM
#9
Thread Starter
Addicted Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|