Question about file content checking

icon315

Member
Is there a way of checking whether a file contains a certain string? I've tried some out, like:

PHP:
string url = visit_url("file:///C:/Users/Noe Canales/Desktop/Kol/data/shot.txt");	
if(contains_text(url, "icon315"))
print("YES!");
and
PHP:
string [int] shooters;
		file_to_map( "hearted.txt" , shooters);
		
		if(contains_text(shooters, "icon315"))
		print("YES!");

None work though


NOTE: GAH! Title Typo :P
Not any more
-lost
 
Last edited by a moderator:
You should use file_to_map(), and since the content of the file is loaded into a map, you should check like this:
PHP:
string [int] shooters;
file_to_map( "hearted.txt" , shooters );

foreach i, str in shooters
        if( contains_text( str, "icon315" ) )
                print("YES!");
 
Thanks. If only I was better at maps.

EDIT:
Ok i can't seem to get this working, i know i screwed up completely somehow, so here is a snippet of my script which shows how i use it.

PHP:
string [int] creamers;
		file_to_map( "creamed.txt" , creamers);
		
			if(THIS COMMAND IS ACTIVATED){
				foreach i, str in creamers //Part which needs 
				if( !contains_text( str, check.to_lower_case() ) ) //Fixing
				{
					//DO STUFF
				}
				else
				{
					//DO OTHER THINGS
				}
 
Last edited:
It started working now...But it seems to do the "else" part even if the "if" statement is true
EDIT: I see what is going on. This is what the .txt file looks like atm:
Code:
0	icon315
1	slyz
Since the first part contains "icon315", it does the "else" part, but the second part does not contain "icon315" so it does the "if" part. How would i make it so that it looks overall if the whole file has "icon315"?
 
Last edited:
It's checking the condition (and doing stuff or other stuff) for each line of the file.
Is suspect you want something like

Code:
int numFound = 0;
foreach i, str in creamers
if ( contains_text( str, check.to_lower_case() ) )
{
  numFound += 1;
}

if (numFound == 0)
{
                    //DO STUFF
}
else
{
                    //DO OTHER THINGS
}

(but this is duck)
 
Last edited:
Or you can do it Zarqon style:
PHP:
string [int] creamers;
file_to_map( "creamed.txt" , creamers);

boolean map_contains( string [ int ] map, string text )
{
	foreach i, str in map
	{
		if ( str.contains_text( text ) ) return true;
	}
	return false;
}

if ( !map_contains( creamers, "icon315" ) )
{
	//DO STUFF
}
else
{
	//DO OTHER THINGS
}

EDIT:
[15:53] phil4011: Icon315 has hit you in the face with a cream pie.
[15:53] phil4011 has hit you in the face with a cream pie.
I guess it worked ^^
 
Back
Top