Author Topic: A string.find problem  (Read 1392 times)

0 Members and 1 Guest are viewing this topic.

Offline blackwings

  • Scripter
  • King
  • ******
  • Posts: 986
  • Karma: +12/-8
A string.find problem
« on: 12 July, 2005, 08:36:10 »
I have started to develop a new mainbot, which is not a small one like BASIC :).

Anyway, now during my development of my new mainbot, I have had many problems with string.find when its format is like this =
string.find(data," ",1,1)

Its especially a problem when useing magic chars with the string.find, but I want to use this format
because its a little bit faster then without the ",1,1" :].

So =
1) can anyone explain what the ",1,1" does
2) is there a different way to use this format(which works with magic chars), like different values?
I have tried several myself but no succes  :(
« Last Edit: 12 July, 2005, 08:36:55 by blackwings »

PtokaX forum

A string.find problem
« on: 12 July, 2005, 08:36:10 »

Offline Mogli

  • Fulll Member
  • ****
  • Posts: 59
  • Karma: +0/-0
(No subject)
« Reply #1 on: 12 July, 2005, 10:32:26 »
well this is from the LUA Manual

? string.find (s, pattern [, init [, plain]])
Looks for the first match of pattern in the string s. If it finds one, then find returns the indices of s
where this occurrence starts and ends; otherwise, it returns nil. If the pattern specifies captures
(see string.gsub below), the captured strings are returned as extra results. A third, optional
numerical argument init specifies where to start the search; its default value is 1 and may be
negative. A value of true as a fourth, optional argument plain turns off the pattern matching
facilities, so the function does a plain ?find substring? operation, with no characters in pattern
being considered ?magic?. Note that if plain is given, then init must be given too.

so the first number, lets you decide where to start,
so putting that to 1 is like not putting it there and
the second turns off the patter matching facilities
so that
string.find( str, "(%S+)" )
will search for  a substring (%S+)
so we would only use this if we are looking for something
specific like a name or so, and only need to know if
its in the string, but as soon as you also want patternmatching, you leave away the second argument

PtokaX forum

(No subject)
« Reply #1 on: 12 July, 2005, 10:32:26 »