Posts: 35
Threads: 5
Joined: Aug 2010
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?
Posts: 1,823
Threads: 20
Joined: Jun 2010
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.
Posts: 35
Threads: 5
Joined: Aug 2010
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.
Posts: 1,823
Threads: 20
Joined: Jun 2010
echo (at $samplestring 1) (at $samplestring 2)
Posts: 35
Threads: 5
Joined: Aug 2010
21 Aug 10, 03:01PM
(This post was last modified: 21 Aug 10, 03:07PM by Breeze.)
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).
Posts: 1,823
Threads: 20
Joined: Jun 2010
21 Aug 10, 03:05PM
(This post was last modified: 21 Aug 10, 03:07PM by Gibstick.)
secondpartofsamplestring = [concat (at $samplestring 1) (at $samplestring 2)]
Use (secondpartofsamplestring)
Tutorial
Posts: 35
Threads: 5
Joined: Aug 2010
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.
Posts: 1,823
Threads: 20
Joined: Jun 2010
That requires loop and listlen and a + and -, in addition to time. Perhaps Bukz can help when he gets online :P
Posts: 35
Threads: 5
Joined: Aug 2010
21 Aug 10, 03:41PM
(This post was last modified: 21 Aug 10, 03:59PM by Breeze.)
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
Posts: 1,823
Threads: 20
Joined: Jun 2010
21 Aug 10, 03:50PM
(This post was last modified: 21 Aug 10, 11:17PM by Gibstick.)
No problem! Glad you could solve it by yourself :)
Posts: 3,462
Threads: 72
Joined: Jun 2010
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.
Posts: 3,780
Threads: 33
Joined: Jun 2010
22 Aug 10, 04:56PM
(This post was last modified: 22 Aug 10, 04:57PM by V-Man.)
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