forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

string.find - strange result

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development
View previous topic :: View next topic  
Author Message
JC



Joined: 02 Jun 2006
Posts: 16

PostPosted: Mon Jun 26, 2006 9:58 am    Post subject: string.find - strange result Reply with quote

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:
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
Back to top
View user's profile Send private message
Drakonite
Site Admin


Joined: 17 Jan 2004
Posts: 989

PostPosted: Mon Jun 26, 2006 10:40 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
JC



Joined: 02 Jun 2006
Posts: 16

PostPosted: Mon Jun 26, 2006 11:16 am    Post subject: Reply with quote

Thanks Drakonite,

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


Does the trick.
Regards,
JC
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Lua Player Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group