[CubeScript] Substring?
#1
Just a quick question. Is there a function like substring in CS? I looked in the Docs, googled it, tried random commands in AC but nothing worked.

Just need something to break "foo is spam" to "foo" and "is spam".
Thanks.


PS. Also is there a var in which the current name is stored?
Thanks given by:
#2
curname
In scripts use ($curname)
For your first question I suppose at would work.
samplestring = "foo is spam"
echo (at $samplestring 0)
(at $samplestring 0) will make it spit out "foo", remember that it starts counting at zero.
Thanks given by:
#3
Thanks!
As for the at command, I need the other bit (i.e. "is spam") separated too. An argc would make everything fine, but I'm not sure CS has one.
Thanks given by:
#4
echo (at $samplestring 1) (at $samplestring 2)
Thanks given by:
#5
lmao I need the whole of the remaining string, not just the second word.
The problem with 'at' is I won't know when to stop for an unknown number of words.
I guess I could iterate through a large amount and stop when at[] returns "" (null string).
Thanks given by:
#6
secondpartofsamplestring = [concat (at $samplestring 1) (at $samplestring 2)]
Use (secondpartofsamplestring)
Tutorial
Thanks given by:
#7
I guess I can't quite get the point across.
I don't know how many words the original string will have. I need a general function to get the remaining part of the string, regardless of the no. of words in it.

eg.
"Do you know"                            ->  "you know"
"Do you know what's worth fighting for?" ->  "you know what's worth fighting for?"

I won't know the number of words each time.
Thanks given by:
#8
That requires loop and listlen and a + and -, in addition to time. Perhaps Bukz can help when he gets online :P
Thanks given by:
#9
There was a listlen?! That solves everything.
In case you're curious:
s = ""
loop i (listlen $arg1) [s = (concat $s (at $arg1 (+ $i 1)))]

EDIT: Thanks a whole lot!
EDIT2: Also found argc: $numargs
Thanks given by:
#10
No problem! Glad you could solve it by yourself :)
Thanks given by:
#11
Nice little conversation ya'll had there. By the way, if you have a question, don't hesitate to ask on the cubescript IRC channel. It is #Cubescript on gamesurge.net. Your bound to get help there.
Thanks given by:
#12
Hm, is there a bigger picture for your script? Whole groups of strings can be treated as a single argument using quotes or brackets.
Also, remember that $numargs is accurate up to 25.
CubeScript tutorials
Thanks given by: