GameMonkey Script

GameMonkey Script Forums
It is currently Mon Jan 21, 2019 12:12 am

All times are UTC




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Custom String Lib Bind
PostPosted: Sun Jun 14, 2009 11:01 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
EDIT: Removed for being too buggy.

This is my custom version of the gm string lib. It's completely redone and has more functions. Some functions have been removed (like the filename/directory functions. I thought they were too specific to filenames and directories for them to be string members).

Quote:
-Entry point. String Builder-
global string String(var1, var2, ...)

-String members-
int Int()
float Float()
string String()
bool IsEmpty()
int Length()
string Left(int count)
string Right(int count)
string Mid(int start, int count)
string TrimLeft()
string TrimRight()
string Trim()
int Compare(string str)
int CompareNoCase(string str)
table Split(string tokens) - Splits the string using tokens. Returns an indexed table of the separate strings
string Delete(int start, int count)
string Remove(string substr)
string RemoveAll(string substr)
string Replace(string substr, string replaceStr)
string ReplaceAll(string substr, string replaceStr)
string Insert(int index, string str)
string Upper()
string Lower()
int Find(string str)
int FindMid(int startPos, string str)
int FindLast(string str)
string Reverse()
bool Match(string mask) - matches the string against a wildcard (eg. "192.168.0.*")
string Letters() - returns just the letters from the string
string Digits() - returns just the digits from the string
string LettersDigits() - returns both letters and digits
string Repeat(int count)
string Set(int index, int value) - Change the char value. Returns a new string with the changed value
int Get(int index) - Get the char value


Example:

Code:
myString = String("Hello", "|", "World"); //returns "Hello|World"

foreach(substr in myString.Split("|"))
{
  print(substr);
}


Last edited by 39ster on Tue Feb 05, 2013 9:23 am, edited 2 times in total.

Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 16, 2009 5:02 am 
Offline

Joined: Sat Apr 25, 2009 1:40 am
Posts: 66
ok after some further testing i fixed a bug in string.Mid() that would return NULL if you did

string.Mid(0, string.Length());


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 16, 2009 10:26 am 
Offline

Joined: Mon Dec 15, 2003 1:38 pm
Posts: 708
Looks good 39ster! Yeah, perhaps a big bunch of file path related functions could go in a Path object, or just be a separate string binding set.


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 16, 2009 12:43 pm 
Offline

Joined: Thu Jan 01, 2004 4:31 pm
Posts: 307
I like the look of this.

I've been thinking for some time that many of GM's standard library functions could be moved to members of the respective type; so table.count() instead of tableCount() and so on.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group