PDA

Click to See Complete Forum and Search --> : Searching for specific text in a string


Kamikaze Badger
September 23rd, 2004, 01:05 AM
For the anti-myg0t plugin I've gotten back to work on, all I need to do is set it up so it will scan a specific string for the term "[myg0t]" and then do the given actions. This would be most easily explained in C, as Small(the scripting language used for Admin mod) is most similar to that in terms of syntax.





Also, if you want to know about myg0t:


http://www.pwned.nl/



Except for the fact that they also hack and crash servers. They seem to be down for now, but you never know when they decide come back.

chsh
September 23rd, 2004, 03:17 AM
Was there a question there?

Kamikaze Badger
September 23rd, 2004, 02:07 PM
Umm... I sort of forgot the question...






The question is, how do you search for specific text in a string? An example in C would be the greatest help.

SwordFish_13
September 24th, 2004, 12:13 PM
Hi

I have no idea what anti-myg0t plugin is and the site URL you gave takes ages to load on my slow-dial up. :(

The question is, how do you search for specific text in a string? An example in C would be the greatest help.

So you want to write a program in C which fiands a Substring in a given string right say

The String is Was there a question there?

and you want to find whether a string question is there in it

thats fairly simple and there are many ways to do it

First and the simplest i belive is to use the function strstr which finds the first occurance of a substring in a given string..........the syntax would be

result=strstr(string1,string2)

the result would return a pointer to the location of the first character of the first occurance of the substring n the string ......else it returns NULL.......now you can modify that to suit your neeeds for examle you found the first occcurence and want to find whether it is there again or not etc etc.....

Or second would be go the long way without using these string functions ...............search for the ocurance of the first character of the substring in the string......for example talking the above string and substring searh for "q" in the string Was there a question there? when you find "q" run a loop 7 time strlen(question) and see if rest of the the 7 characters after that "q" are similar if yes success else not found ....try it your self if you have any problem let us know........:)

--Good Luck--

Kamikaze Badger
October 3rd, 2004, 05:49 AM
Ok... as usual, I didn't get much out of what you said(being that C is an evil language, IMO, and that the scripting language used for Admin Mod is most similar to C... yea...)



So the strstr searches the two strings given for the first occurance of the substring? And then returns a pointer?



Excuse my n00bness, but what's a pointer?

SwordFish_13
October 3rd, 2004, 07:55 AM
HI,

So the strstr searches the two strings given for the first occurance of the substring? And then returns a pointer?

Yes.

It is a Function that takes two arguments both strings and returns a pointer to the occurance of the first argumrnt in the second ............else returns NULL

Excuse my n00bness, but what's a pointer?

Pointer is a variable that contains the address of another variable.

e.g

when you declare a variable say char str[5]

5 consicutive locations are allocated for str in the memory.........all of them can be independently addressed........when i say

ptr= &str;

The base address of the variable str (first of the 5 consituve location) will be passd on to the ptr.................ptr is a pointer to str

Hope this helps .......



--Good Luck--