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/AppGameKit Studio Showcase / [Code Tier1] Additional String Functions

Author
Message
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 17th May 2015 23:14 Edited at: 17th May 2015 23:33
Hi,

There are quite a few string functions which would be very handy if AppGameKit included them as standard but since it doesn't (at time of writing) here are a few to play with:

replaceString()
replaces one or more occurrences of a string with another if found inside the 'source' string

insertString()
inserts a string inside another at the requested position

rightFrom()
returns a string that is the right of the source string except for the number of characters specified by 'pos'

extractString()
returns whatever appears in the source string between the two strings passed to it

removeString()
returns the 'source' string without the 'remove' part in it

instr()
returns the position of a string inside another

countString()
returns the number of times one string appears within another

quote()
returns a string inside double quotes

padLeft()
inserts a number of characters to the left of the source string.
Handy for displaying a score for example:
456 becomes 00456

padRight()
Much like padLeft but to the right instead



AGK V2 user - Tier 1 (mostly)
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 17th May 2015 23:52
More useful functions, thanks!

Quidquid latine dictum sit, altum sonatur
TutCity is being rebuilt
Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 17th May 2015 23:59
You're very welcome

AGK V2 user - Tier 1 (mostly)
Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 12th Aug 2015 20:08
Hi Scraggle.
I'm working on a project that uses strings and was disappointed AGK2 doesn't provide a great number of options. Then I found your list of additional string functions and must say how much they are badly needed. I hope these can be added soon.

I am however struggling with your extractString() function and wonder if you could post an example if you get a spare moment.

Well done, great work.

Battoad
AGK Developer
17
Years of Service
User Offline
Joined: 12th Feb 2007
Location: A Dark Place
Posted: 12th Aug 2015 21:39
ok got it. I used left$ as the end string thinking I needed the string to the left of this and then I used right$ as the start string, again thinking I needed the string to the right of this.
Reversing my strings does make sense in your code but I misinterpreted.
It works fine except with very long strings the Instr() seems to be a bit slow.

Nevertheless, well done and thank you for sharing.

Scraggle
Moderator
21
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 18th Aug 2015 14:03
Glad you got it working.
I haven't come across the speed issue but then I haven't used very large strings.
It is perfectly understandable that it would slow down with large strings though but that is just the nature of the beast.
The only way to speed it up is to convert the code to Tier 1 (or 2 - I can never remember which is which - the C++ version) because then the loops will run much faster.

AGK V2 user - Tier 1 (mostly)

Login to post a reply

Server time is: 2024-11-22 06:48:28
Your offset time is: 2024-11-22 06:48:28