Split Function Needed!

Discussion and feedback on Construct 2

Post » Sat Jan 07, 2012 12:59 am

type: General Function

expression: Split(string1, string2, index)

example usage:
MyString1 = "hi;hello;hey"
MyString2 = Split(MyString1, ";", 0) - (Would return "hi")
MyString2 = Split(MyString1, ";", 1) - (Would return "hello")
MyString2 = Split(MyString1, ";", 2) - (Would return "hey")


what it does:
string1 is the string to split
string2 is the string/character to split string1 by
index is the index of the split to return


another example:
Str1 = "mr,mrs,miss"
Str2 = Split(Str1, ",", 1) - would return "mrs"

Hope this is understandable!

Thank-you!dcrew2012-01-07 01:00:51
B
17
S
4
G
5
Posts: 226
Reputation: 4,042

Post » Sat Jan 07, 2012 1:38 am

tokenat(src, index, separator)
Return the Nth token from src, splitting the string by separator. For example, tokenat("apples|oranges|bananas", 1, "|") returns oranges.

System expressions in the manual

Unless I missed something.
New to Construct ? Where to start

Image Image
Image Image

Please attach a capx to any help request or bug report !
Moderator
B
247
S
85
G
40
Posts: 6,999
Reputation: 57,793

Post » Sat Jan 07, 2012 1:41 am

Yeah, as Kyatric posted, there's even an expression to get the number of tokens.

tokencount(src, separator)
Count how many tokens occur in src using separator. For example, tokencount("apples|oranges|bananas", "|") returns 3.
Image Image
B
161
S
48
G
90
Posts: 7,354
Reputation: 66,763


Return to Construct 2 General

Who is online

Users browsing this forum: MatheusCastellar and 18 guests