@Simeon
Here is an example of a simulated search function using some ghost characters that I mentioned in another thread. Since I can’t read an actual file, I put some sample code in a string that I search. I set up some left and right ghost characters, but there are more characters that need to be added. I wanted to change the color of the found characters, but instead I just show them below the simulated code line. Just follow the instructions on the screen, keying each character slowly and watching what gets matched below the simulated code line. After each set, press the backspace key to clear everything for the next search.
Dave
-- Simulate a search function using ghost characters
function setup()
displayMode(FULLSCREEN)
st=""
str = ""
str2=""
showKeyboard()
font("courier")
-- since I can't read a file, I put simulated code in a string
str1=" counter=1234 count[xx] =1.23 coun-12 cou[x]=12 co[12]= 1. c=.3 u xxx "
g_left="[%[( .=-]" -- some left ghost characters within []
g_right="[ .=()%]%[-]" -- some right ghost characters within []
end
function draw()
background(30,30,0,255)
stroke(255)
strokeWidth(6)
fill(255)
text(st,160,900)
text(str1,10,800)
text(str2,10,780)
text("Simulated a search function using right and left ghost characters",30,980)
text("Simulated code",30,820)
text("Search string with left & right ghost characters",30,920)
text("Key in the word counter and watch below the simulated code line.",30,580)
text("Press the backspace key before keying each of the next strings",30,540)
text("Key in xxxx",30,500)
text("Key in uu",30,480)
text("Key in the number 12345",30,460)
text("Key in 1.234",30,440)
text("Key in .30",30,420)
fill(255, 0, 0, 255)
rectMode(CENTER)
textMode(CENTER)
rect(200,700,200,50)
fill(255)
text(str,200,700)
rectMode(STANDARD)
textMode(STANDARD)
end
-- accept a key from the keyboard
function keyboard(key)
if key == BACKSPACE then
st="" -- clear variables
str = ""
str2=""
return
end
-- some of the magic characters, proceed them with a %
if key == "." or key == "%" or key == "[" or key == "]" then
str = str.."%"
end
str = str..key
search(str)
end
-- search the string str1 for the keyed string
function search(ss)
sx=1
-- setup search string with left and right ghost characters
st = g_left..ss..g_right
str2=""
while sx < string.len(str1) do
s,e = string.find(str1,st,sx)
if s ~= nil then
fillstr(s+1,e-1)
sx = s+1
elseif s == nil then
return
end
end
fillstr() -- show found strings
end
-- I didn't know how to change the color of the text so I just
-- show the characters that are found below the str1 line.
function fillstr(s,e)
for x=string.len(str2)+1,e do
if x>= s and x<=e then
xx=string.sub(str1,x,x)
else
xx=" "
end
str2 = str2..xx
end
end