Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   Split String Into Separate Characters? (https://forums.graalonline.com/forums/showthread.php?t=75197)

wild8900 07-09-2007 09:48 AM

Split String Into Separate Characters?
 
Hey how do I split a string into separate characters using a function similar to tokenize?

Twinny 07-09-2007 11:54 AM

I'm not sure if there is a function to split a string into an array by characters. I made an example one for you.

PHP Code:

function onCreated()

  
this.string "Splitting a string by characters";
  
temp.array = splitstring(this.string);
  echo(
temp.array);
}

function 
splitstring(string)
{
  for (
t=0string.length(); t++)
  {
    if (
string.substring(t,1) != " ")
    {
      
temp.array.add(string.substring(t,1));
    }  
  }
  return 
temp.array;


Echo'd 'S,p,l,i,t,t,i,n,g,a,s,t,r,i,n,g,b,y,c,h,a,r,a,c,t ,e,r,s'. I didn't add spaces by default but you can change that if need be. Hope this helps.

zokemon 07-09-2007 12:25 PM

temp.t Please!

Twinny 07-09-2007 01:03 PM

Quote:

Originally Posted by zokemon (Post 1327194)
temp.t Please!

For() loops should automatically make the variables temporary ones...

zokemon 07-09-2007 04:15 PM

Quote:

Originally Posted by Twinny (Post 1327198)
For() loops should automatically make the variables temporary ones...

Oh? I've been in such a habit to spam temp. everywhere that I see that I would have no way of knowing this.

cbk1994 07-11-2007 10:53 PM

Quote:

Originally Posted by zokemon (Post 1327232)
Oh? I've been in such a habit to spam temp. everywhere that I see that I would have no way of knowing this.

That's what I do.

on Java,

PHP Code:

for ( int i 05++ ) 

the variable 'i' is contained in the for and is not made global like if you were to do:

PHP Code:

int i;
for ( 
05++ ) 

Perhaps Graal does something similar?

Skyld 07-12-2007 12:18 AM

Quote:

Originally Posted by cbkbud (Post 1328340)
...

Perhaps Graal does something similar?

I think Graal scopes variables to the function, not to the block.


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

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