A string.find problem
 

News:

29 December 2022 - PtokaX 0.5.3.0 (20th anniversary edition) released...
11 April 2017 - PtokaX 0.5.2.2 released...
8 April 2015 Anti child and anti pedo pr0n scripts are not allowed anymore on this board!
28 September 2015 - PtokaX 0.5.2.1 for Windows 10 IoT released...
3 September 2015 - PtokaX 0.5.2.1 released...
16 August 2015 - PtokaX 0.5.2.0 released...
1 August 2015 - Crowdfunding for ADC protocol support in PtokaX ended. Clearly nobody want ADC support...
30 June 2015 - PtokaX 0.5.1.0 released...
30 April 2015 Crowdfunding for ADC protocol support in PtokaX
26 April 2015 New support hub!
20 February 2015 - PtokaX 0.5.0.3 released...
13 April 2014 - PtokaX 0.5.0.2 released...
23 March 2014 - PtokaX testing version 0.5.0.1 build 454 is available.
04 March 2014 - PtokaX.org sites were temporary down because of DDOS attacks and issues with hosting service provider.

Main Menu

A string.find problem

Started by blackwings, 12 July, 2005, 08:36:10

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

blackwings

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  :(


Mogli

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

SMF spam blocked by CleanTalk