#1
Posted 04 August 2015 - 11:20 PM
I need to "read" a line by it pos , like this:
str = "why you do that?"
3rd_word = findbypos(9,10)
print(3rd_word)
return:
"do"
#2
Posted 04 August 2015 - 11:31 PM
local myString = "This is a string" local str = myString:find(6,7) --#Can be string.find(myString,6,7) print(str) --# "is"
#3
Posted 04 August 2015 - 11:35 PM
Dragon53535, on 04 August 2015 - 11:31 PM, said:
local myString = "This is a string" local str = myString:find(6,7) --#Can be string.find(myString,6,7) print(str) --# "is"
local myString = "This is a string" local str = myString:sub(6,7) --#Can be string.sub(myString,6,7) print(str) --# "is"
#4
Posted 04 August 2015 - 11:40 PM
#5
Posted 05 August 2015 - 05:15 PM
archive1 :
hey i am
a archive
and i have
words on
lines
---------------
code:
function that reads the archive1 and prints on the screen
----------
the X will reset to one at each line end?
if you don't understand i can try to explain again.
#6
Posted 05 August 2015 - 05:24 PM
local x, y = 1, 1 term.clear() --# Clear the screen local file = fs.open( "<filename>", "r" ) for line in file.readLine do -- #Loop through all the lines in the file term.setCursorPos( x, y ) --# Set the cursor position term.write( line ) --# Write the line y = y + 1 endIf I'm incorrect then please explain further on what you meant
Edited by TheOddByte, 05 August 2015 - 05:25 PM.
#7
Posted 05 August 2015 - 05:29 PM
Here is:
I making a web browser, and to add a click support , to click on the screen on a text and go to an other link, I need the browser to scan for a especific word, and then see the X and Y pos of it, if you click in the pos you go to the link, and I having problems with this code because the X pos is a little strange of the supposed to be.I think is because the function don't know when the string is on another line.
Edited by lukasloko, 05 August 2015 - 05:29 PM.
#8
Posted 05 August 2015 - 05:35 PM
#9
Posted 05 August 2015 - 05:42 PM
--# Store all lines in a table
local lines = {}
--# Get all the lines from the file
local file = fs.open( "<your file>", "r" )
for line in file.readLine do
table.insert( lines, line )
end
--# This function will loop through all the lines
--# And check if it can find the specific word in any line
--# It will return a table like this: { x1 = 1, x2 = 2, y = 1 }
local function find( word )
local results = {}
for i, v in pairs( lines ) do --# Loop through all the lines
if line:find( word ) then --# Check and see if you can find the specific word in the line
local x1, x2 = line:find( word ) --# Get the first and last position of the word
table.insert( results, {
x1 = x1;
x2 = x2;
y = i;
})
end
end
end
local results = find( "Hello" )
print( textutils.serialize( results ) )
This is just an example, if you understood what I did here then it can probably be helpful to you, the question is, do you want to find a word by it's position? or do you want to search for it as a string( string.find( str, str2 ) )Edit: Try creating a file and put some random text in it, and put Hello somewhere in it and see if it returns the result you expect it to return
Edited by TheOddByte, 05 August 2015 - 05:43 PM.
#10
Posted 05 August 2015 - 05:43 PM
Edited by lukasloko, 05 August 2015 - 05:44 PM.
#11
Posted 05 August 2015 - 07:14 PM
TheOddByte, on 05 August 2015 - 05:42 PM, said:
--# Store all lines in a table
local lines = {}
--# Get all the lines from the file
local file = fs.open( "<your file>", "r" )
for line in file.readLine do
table.insert( lines, line )
end
--# This function will loop through all the lines
--# And check if it can find the specific word in any line
--# It will return a table like this: { x1 = 1, x2 = 2, y = 1 }
local function find( word )
local results = {}
for i, v in pairs( lines ) do --# Loop through all the lines
if line:find( word ) then --# Check and see if you can find the specific word in the line
local x1, x2 = line:find( word ) --# Get the first and last position of the word
table.insert( results, {
x1 = x1;
x2 = x2;
y = i;
})
end
end
end
local results = find( "Hello" )
print( textutils.serialize( results ) )
This is just an example, if you understood what I did here then it can probably be helpful to you, the question is, do you want to find a word by it's position? or do you want to search for it as a string( string.find( str, str2 ) )Edit: Try creating a file and put some random text in it, and put Hello somewhere in it and see if it returns the result you expect it to return
#12
Posted 05 August 2015 - 07:23 PM
#13
Posted 05 August 2015 - 08:29 PM
#14
Posted 05 August 2015 - 08:41 PM
flaghacker, on 05 August 2015 - 08:29 PM, said:
It is possible, but as flaghacker pointed out, it's something that won't work that great. You would actually want a system that's more advanced than this. You could go with how HTML does this (and many other GUI frameworks), by having each object (a button, textbox or simply text) be a separate object. I'm talking about an Object-Oriented Programming (OOP) approach. It's really something that might not be as easy as you might expect, so my suggestion would be to first make some simpler programs, like a door lock with clickable buttons on a monitor. Also, you could look and see how different button APIs handle buttons.
#15
Posted 05 August 2015 - 10:30 PM
flaghacker, on 05 August 2015 - 08:29 PM, said:
MKlegoman357, on 05 August 2015 - 08:41 PM, said:
flaghacker, on 05 August 2015 - 08:29 PM, said:
It is possible, but as flaghacker pointed out, it's something that won't work that great. You would actually want a system that's more advanced than this. You could go with how HTML does this (and many other GUI frameworks), by having each object (a button, textbox or simply text) be a separate object. I'm talking about an Object-Oriented Programming (OOP) approach. It's really something that might not be as easy as you might expect, so my suggestion would be to first make some simpler programs, like a door lock with clickable buttons on a monitor. Also, you could look and see how different button APIs handle buttons.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users











