Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   New Scripting Engine (GS2) (https://forums.graalonline.com/forums/forumdisplay.php?f=153)
-   -   String Contains? (https://forums.graalonline.com/forums/showthread.php?t=66841)

Omini 06-22-2006 06:58 PM

String Contains?
 
How do I do

NPC Code:
if (strcontains(,)) { }



in GS2? I checked the basic scripting page and it's not there...

Quote:

Originally Posted by Basic Scripting Page (Graal Wiki)
obj.type() - gets the type of the var (float 0, string 1, object 2, array 3)
obj.length() - string length
obj.trim() - removes spaces from the front and back of a string
obj.lower() - converts a string to lower case
obj.upper() - converts a string to upper case
obj.tokenize([delimiters])
obj.charat(pos)
obj.pos(substring)
obj.starts(string)
obj.ends(string)
obj.substring(index[,length])
obj.size() - array length
obj.subarray(index[,length])
obj.addarray(obj2)
obj.insertarray(index,obj2)
obj.index(obj2) - position of obj2 in the array
obj.clear()
obj.add(obj2)
obj.delete(index)
obj.remove(obj2)
obj.replace(index,obj2)
obj.insert(index,obj2)

Can anyone help me out?

JustBreathe 06-22-2006 07:03 PM

Quote:

Originally Posted by Omini
How do I do

NPC Code:
if (strcontains(,)) { }



in GS2? I checked the basic scripting page and it's not there...



Can anyone help me out?

PHP Code:

function containsstrStackstrNeedle )
  { 
// Usage: container( this.var, "foo" );
  
for ( 0strStack.length() - strNeedle.length(); ++ )
    if ( 
strStack.substringistrNeedle.length()) == strNeedle)
      return 
true;
  return 
false;
  } 


ApothiX 06-22-2006 07:05 PM

Quote:

Originally Posted by JustBreathe
PHP Code:

function containsstrStackstrNeedle )
  { 
// Usage: container( this.var, "foo" );
  
for ( 0strStack.length() - strNeedle.length(); ++ )
    if ( 
strStack.substringistrNeedle.length()) == strNeedle)
      return 
true;
  return 
false;
  } 


:X not needed dude.

if(foo.pos("bar") >= 0) {
}

JustBreathe 06-22-2006 07:06 PM

Quote:

Originally Posted by ApothiX
:X not needed dude.

if(foo.pos("bar") >= 0) {
}

^^; True. I just took segments from my replaceAll( strStack, strNeedle, strReplace) function.

ApothiX 06-22-2006 07:08 PM

Quote:

Originally Posted by JustBreathe
^^; True. I just took segments from my replaceAll( strStack, strNeedle, strReplace) function.

ARGH! You are using contiga's style. >:[
Why the hell is he getting you guys to use it?

JustBreathe 06-22-2006 07:10 PM

Quote:

Originally Posted by ApothiX
ARGH! You are using contiga's style. >:[
Why the hell is he getting you guys to use it?

Err... I wrote that too quickly, I guess. I usually do ( str ). ( As you could see in the first function I supplied. I think you're over-reacting... )

ApothiX 06-22-2006 07:13 PM

Quote:

Originally Posted by JustBreathe
( As you could see in the first function I supplied. I think you're over-reacting... )

>> if ( strStack.substring( i, strNeedle.length()) == strNeedle)

Alright, it's good that you don't use that style. It's just super annoying to see people use it.

Omini 06-22-2006 08:11 PM

so in the same sense as the Wiki puts it, it would be

if(obj.pos(obj2) >= 0) { }

Yeah?

JustBreathe 06-22-2006 08:12 PM

Quote:

Originally Posted by Omini
so in the same sense as the Wiki puts it, it would be

if(obj.pos(obj2) >= 0) { }

Yeah?

Try it and see!

CheeToS2 06-22-2006 08:48 PM

It's easier to use .contains()

this.msg = "what npc";
this.findmsg = "npc";

if (this.msg.contains(this.findmsg)) {
// whatever
}

JustBreathe 06-22-2006 08:52 PM

Quote:

Originally Posted by CheeToS2
It's easier to use .contains()

this.msg = "what npc";
this.findmsg = "npc";

if (this.msg.contains(this.findmsg)) {
// whatever
}

GraalScript: Function contains not found at line 6 in script of SandBox (in level onlinestartlocal.nw at pos (30.5, 30))

ApothiX 06-22-2006 09:06 PM

Quote:

Originally Posted by Omini
so in the same sense as the Wiki puts it, it would be

if(obj.pos(obj2) >= 0) { }

Yeah?

Isn't that what I said? O_o

Omini 06-22-2006 09:21 PM

Quote:

Originally Posted by CheeToS2
It's easier to use .contains()

this.msg = "what npc";
this.findmsg = "npc";

if (this.msg.contains(this.findmsg)) {
// whatever
}

Ah-ha! So that DOES work... I guess I used (this.msg.contains() text) or something stupid.

Quote:

Originally Posted by ApothiX
Isn't that what I said? O_o

Yeah sorta. You said if (foo.pos("bar") >= 0) { }, with the foo.pos sorta confusing me. I just wanted to clarify.

ApothiX 06-22-2006 09:29 PM

Quote:

Originally Posted by Omini
Ah-ha! So that DOES work... I guess I used (this.msg.contains() text) or something stupid.

Quote:

Originally Posted by JustBreathe
GraalScript: Function contains not found at line 6 in script of SandBox (in level onlinestartlocal.nw at pos (30.5, 30))

Hmm?


Quote:

Originally Posted by Omini
Yeah sorta. You said if (foo.pos("bar") >= 0) { }, with the foo.pos sorta confusing me. I just wanted to clarify.

Ah, I see. Well yes, that is how you do it.


EDIT: Ogasp, post #1234. I r winnar.

xAndrewx 06-23-2006 01:42 AM

I use this method, I'm sure it works too.

PHP Code:

function onCreated()
{
  
temp.test = {"hey""test"};
  if (
contains(temp.test"test")) //If 'test' is in temp.test, it'll echo 'Found' to the NC users
  
{
    echo(
"Found");
  }
    else
  {
    echo(
"Not Found");
  }



ApothiX 06-23-2006 02:20 AM

Quote:

Originally Posted by xAndrewx
I use this method, I'm sure it works too.

PHP Code:

function onCreated()
{
  
temp.test = {"hey""test"};
  if (
contains(temp.test"test")) //If 'test' is in temp.test, it'll echo 'Found' to the NC users
  
{
    echo(
"Found");
  }
    else
  {
    echo(
"Not Found");
  }



Same thing as the in operator? if("test" in temp.test) {?
He is trying to compare substrings, not check if a value is in an array, I believe.

xAndrewx 06-23-2006 09:19 AM

Oh I see, my mistake.

Admins 06-23-2006 10:57 AM

Yes the replacement for strcontains(oldstring,oldstring) is contains(string,string)

ApothiX 06-24-2006 07:41 AM

Quote:

Originally Posted by Stefan
Yes the replacement for strcontains(oldstring,oldstring) is contains(string,string)

It's not obj.contains(string) ?


All times are GMT +2. The time now is 06:44 AM.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.