View Full Version : read a ascii code from a file and get the number of the ascii code
can i read a ascii code from a file and get the number of the ascii code?
the code
code = String.Asc("h");
i get a code = 104 bat i whot to get a ascii from a file (not a text file) i dont wont the "h" i wont a ascii from a file and get the number
read the file into a string ( TextFile.ReadToString )
Then use String.Asc to get the value of the character. If you're looking to get a particualr character, then you might need to use String.Mid to single out that character. Or you could use a loop to iterate through the entire string to get the Asc value of all characters.
TJ_Tigger
09-24-2006, 09:56 AM
the code
code = String.Asc("h");
i get a code = 104 bat i whot to get a ascii from a file (not a text file) i dont wont the "h" i wont a ascii from a file and get the number
Are you using the io.open to read in a binary file? You then want to read the binary to an ascii character? Is that what you want to do?
If that is the case you can use some of the built-in lua functions. string.format will output your data as hex if you want or tonumber allows you to format a number in the base you want (base 2 for binary, base 10 for decimal system and base 16 for hex).
i dont use io.open i dont anderstent it and i wont to read the binary to an ascii character
to worm
i cnot use the TextFile.ReadToString bekose the file is not a text file
i think i need a help in io.open i need an example (not the link to the site bekose i dont andersten it)
TJ_Tigger
09-24-2006, 11:49 AM
Can you post a file you would like to read? And explain what it is you are wanting to do with that file after it has been read into AMS? And are there certain bits you are wanting to convert or is it all bits?
Tigg
i wont to copy a file (file.mp3) to (file2.mp3) but byte after byte ascii after ascii
Yes, but for what reason?
i need it. can anibady help me? i wont to delete sum ascii code and chek samting
if i build a code in visual basic 6 sambady can help me to save it to DLL and use it in ams6?
the code in visual basic 6
--------------------------------------------------------------
Public str1 As Byte
Open App.Path & "\1.mp3" For Binary As #1
Open App.Path & "\2.mp3" For Binary Access Write As #2
Do Until EOF(1)
Get #1, , str1
Put #2, , str1
Loop
Close #1
Close #2
-----------------------------------------------------------------
TJ_Tigger
09-24-2006, 08:22 PM
I think something like this might work
local inp = assert(io.open("1.mp3", "rb"));
local out = assert(io.open("2.mp3", "wb"));
local data = inp:read("*.all");
--make changes to the data here
out:write(data);
assert(out:close());
Tigg
error in - local data = inp:read("*.all"); the error is invalid format
local inp = assert(io.open("c:\\1.jpg", "rb"));
local out = assert(io.open("c:\\2.jpg", "wb"));
local data = inp:read();
Label.SetText("Label1", data);
--make changes to the data here
out:write(data);
assert(out:close());
if i set the text to a label then the data = mor the 1 ascii code and i need only 1 ascii then a loop to all the file
the code to all
local inp = assert(io.open("c:\\1.jpg", "rb"));
local out = assert(io.open("c:\\2.jpg", "wb"));
-- A for loop that counts from 1 to 10
min = 1; -- The number to start at
max = 100; -- The number to stop at
for count = min, max do
local data = inp:read(1);
--Label.SetText("Label1", data);
--make changes to the data here
out:write(data);
end
assert(out:close());
TJ_Tigger
09-25-2006, 08:07 AM
local inp = assert(io.open("c:\\1.jpg", "rb"));
local out = assert(io.open("c:\\2.jpg", "wb"));
while true do
local byte = inp:read(1);
if not byte then break end
Label.SetText("Label1", byte);
--make changes to the data here
if byte == "something" then byte = "somethingelse" end
out:write(byte);
end
assert(out:close());
You could try something like the above as well. This will continue to loop until you reach the end of the file and during each loop it will return one byte at a time. You can then make your change and output that byte to the output file.
Tigg
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.