string.find - strange result

Discuss using and improving Lua and the Lua Player specific to the PSP.

Moderators: Shine, Insert_witty_name

Post Reply
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

string.find - strange result

Post by JC »

I am getting a 'strange' result using string.find to find a '.' (full stop) in a string. The function always returns 1 regardless of where the full stop is. The code below illustrates the issue. It prints two numbers the top one should be the position of the full stop within the string "abcdef.", but always returns 1.
The second line shows the correct behaviour for the letter e. Am I doing something silly here ?

Code: Select all

screen:print(10,10,string.find("abcdef.","."),Color.new(255,255,255))
screen:print(10,20,string.find("abcdef.","e"),Color.new(255,255,255))


screen:flip()
screen.waitVblankStart()


pad = Controls.read()
while not pad:start() do
  pad = Controls.read()
end
TIA,
JC
User avatar
Drakonite
Site Admin
Posts: 990
Joined: Sat Jan 17, 2004 1:30 am
Contact:

Post by Drakonite »

string.find doesn't just search for a string, it searches for a pattern. This page gives more info. If you do something such as string.find("abcdef.",".",1,true) it will disable pattern matching and just search for the string.
Shoot Pixels Not People!
Makeshift Development
JC
Posts: 16
Joined: Fri Jun 02, 2006 9:30 am

Post by JC »

Thanks Drakonite,

Code: Select all

string.find("abcdef.",".",1,true) 


Does the trick.
Regards,
JC
Post Reply