Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Split String into an array AGK 2 Tier 1

Author
Message
BuccaneerBob
AGK Developer
14
Years of Service
User Offline
Joined: 18th Aug 2010
Location: Canada
Posted: 6th Dec 2014 16:23
Without having to migrate to Tier 2, is there a way to split a string into an array in AppGameKit 2 Tier 1? A way to parse data? If not, think this could be something to request for future builds?

Example:

global RawData as String
global ParsedData[] as String
RawData = "This,is,a,comma,seperated,string"
ParsedData = Split(RawData)

So the result would be
ParsedData[0] = This
ParsedData[1] = is
ParsedData[2] = a
ParsedData[3] = comma
ParsedData[4] = seperated
ParsedData[5] = string

Robert Janes (Samu Games)
http://www.samugames.com/artifact
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Dec 2014 17:13 Edited at: 6th Dec 2014 17:14
GetStringToken

Description


Returns a specific token from a string separated by the given delimiters, for example a string containing "first:second:third" has three tokens delimited by ":" and "first:second;third" has three tokens separated by the delimiters ":;". You can have multiple delimiters between each token, for example "first:;second:third" is valid, and has three tokens. In tier 2 the returned string must be deleted when you are done with it. You can use CountStringTokens to count the number of tokens in the string

Quidquid latine dictum sit, altum sonatur
BuccaneerBob
AGK Developer
14
Years of Service
User Offline
Joined: 18th Aug 2010
Location: Canada
Posted: 6th Dec 2014 18:37
Not sure how I missed this!

Thanks a ton BatVink!

Robert Janes (Samu Games)
http://www.samugames.com/artifact
feiting shadow
18
Years of Service
User Offline
Joined: 12th Sep 2006
Location:
Posted: 10th Dec 2014 17:52


I tested this. But I realized the arrays are 1 based, so you gotta print each string from 1 to length. Interesting that it just copies the same value in 0.

I saw this and was like "I can see why they did this, but it should still have a function".

Also, modifying this to ref the array might do better performance.

Signed
------
paulrobson
10
Years of Service
User Offline
Joined: 22nd Nov 2014
Location: Norfolk, England
Posted: 10th Dec 2014 18:35
Depends really. If you are used to python with split() you kind of automatically think about splitting it into an array. It is entirely possible that with the Count/Get Token functions you are just duplicating stuff and you can keep it in its original format.

Login to post a reply

Server time is: 2024-11-25 13:20:08
Your offset time is: 2024-11-25 13:20:08