Graal Forums  

Go Back   Graal Forums > Development Forums > Tech Support
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-19-2006, 06:53 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Unexpected Results

PHP Code:
function onCreated()
  {
  
this.string = new TStaticVar();
  
this.string.n.one 1;
  
this.string.n.two 2;
  
  
temp.arr this.string.savevarstoarray(0);
  for ( 
atemp.arr )
    if ( 
containsa) )
      echo( 
);
  } 
When b = "two": n.two=2
When b = "n": n.two=2,n.one=1
When b = "one": n.one=1

When b = "t": ... Nothing.
When b = "o": ... Nothing.
When b = "n.": ... Nothing.
When b = "=": ... Nothing.

When b = "1": n.one=1

Summary:
When using the 'contains' function, the results vary. By deduction, we can see that if a string contains "two", than it must contain "t", however... It returns false.

It seems like the string is split by symbols ( ., =, " ", etc etc ) and then they are compared token[x] == needle.

Working Version:
PHP Code:
function containshaystackneedle )
  {
  if ( 
haystack.type() == )
    return 
false;
  
  for ( 
0=< haystack.length() - needle.length(); ++ )
    {
    if ( 
haystack.substringineedle.length() ) == needle )
      return 
true;
    }

  return 
false;
  } 
Reply With Quote
  #2  
Old 10-19-2006, 07:14 AM
Novo Novo is offline
[TServerDeveloper]
Join Date: Jun 2006
Posts: 448
Novo will become famous soon enough
Thinking about it... contains is probably for arrays... If that's the case, I guess the results would be a little more expected...

But -- If that's the case: would there be a 'contains' for strings?
Reply With Quote
  #3  
Old 10-19-2006, 09:35 AM
Skyld Skyld is offline
Script-fu
Skyld's Avatar
Join Date: Jan 2002
Location: United Kingdom
Posts: 3,914
Skyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud ofSkyld has much to be proud of
Send a message via AIM to Skyld
Yes contains() is for arrays I believe.

I think you can use haystack.pos(needle) >= -1 to check for an occurence in a string.
Reply With Quote
  #4  
Old 10-19-2006, 02:02 PM
Admins Admins is offline
Graal Administration
Join Date: Jan 2000
Location: Admins
Posts: 11,693
Admins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud ofAdmins has much to be proud of
Contains() is checking for substrings which are enclosed with one of those characters:
".,;:-_><|!\"$%&/\\()=?`{[]}+*~#''^ "

Example: contains("hello you","you") = true
The text "two" is not containing a word "t"
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 10:14 AM.


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