Version 1.03 Added an additional function called ListCompare.
========= ========== =========== =========
Version 1.02 Bug Fixes and such.
========= ========== =========== =========
Version 1.01
WizardStorm Think Group is pleased to present to you three addional String Functions
and nine new List functions. We think you will find these functions invaluable in your
future projects. Enjoy!!!
If you find any bugs or want to suggest adding something to this library,
please post below or send an email to [email protected]
/****************************************
STRING FUNCTIONS
****************************************/
//Description: Removes the leading/trailing spaces from either the LEFT,
//RIGHT or BOTH ends of a sString. Default = BOTH.
//Returns: A copy of sString with the specified end trimmed of leading/trailing spaces.
string GetStringTrim(string sString, string sTrimEnd="BOTH");
//Description: Extracts a SubString from a String.
//Returns: A string; the set of characters from sString, beginning at nStart,
//of length nCount.
string GetStringMid(string sString, int nStart, int nCount);
//Description: Replaces all instances of sOldSubString with sNewSubString.
//By default, this is Case Sensitive, but this can be set to be Non-Case Sensitive.
//Returns: A copy of sString with all instances of sOldSubString replaced with sNewSubString.
string StringReplaceAll(string sString, string sOldSubString, string sNewSubString, int nCaseSensitive=TRUE) ;
/****************************************
LIST FUNCTIONS
****************************************/
//Descrption: Gets the first element of a list.
//Returns: The first element of a list. If the list is empty, returns an empty string.
string ListGetFirst(string sList, string sDelimiters=",") ;
//Descrption: Gets the last element of a list.
//Returns: The last element of a list. If the list is empty, returns an empty string.
string ListGetLast(string sList, string sDelimiters=",") ;
//Descrption: Gets the number of elements in a list.
//Returns: The number of elements in list.
int ListLen(string sList, string sDelimiters=",") ;
//Descrption: Gets the list element at a specified index.
//Returns: The element at a specified index. If element is empty at the specified index,
//returns a empty string.
string ListGetAt(string sList, int nIndex, string sDelimiters=",");
//Descrption: Inserts an element at the end of a list.
//Returns: A copy of the list, with sValue appended.
string ListAppend(string sList, string sValue, string sDelimiters=",");
//Descrption: Inserts an element at the beginning of a list.
//Returns: A copy of the list, with sValue inserted at the first position.
string ListPrepend(string sList, string sValue, string sDelimiters=",");
//Descrption: Deletes the element from a list at the specified index.
//Returns: A copy of the list, without the specified element.
string ListDeleteAt(string sList, int nIndex, string sDelimiters=",");
//Descrption: Inserts an element in a list at a specified index.
//Returns: A copy of the list, with the value inserted at the specified index.
string ListInsertAt(string sList, int nIndex, string sValue, string sDelimiters=",");
//Descrption: Replaces the contents of a list element.
//Returns: A copy of the list, with the new value assigned to the element at a specified index.
string ListSetAt(string sList, int nIndex, string sValue, string sDelimiters=",");
//Descrption: Changes a list delimiter.
//Returns: A copy of the list, with each delimiter character replaced with sNewDelimiter.
string ListChangeDelimiter(string sList, string sNewDelimiter, string sDelimiters=",");
//Descrption: Determines the index of the first list element that contains sSubString,
//not neccessarily equal to.
//If nCaseSensitive equals TRUE, the result will consider case in the search.
//Returns: Index of the first list element that contains sSubstring. If not found, returns 0.
int ListContains(string sList, string sSubString, int nCaseSensitive=TRUE, string sDelimiters=",");
//Descrption: Counts the instances of a specified value in a list.
//If nCaseSensitive equals TRUE, the result will consider case in the search.
//If nExactMatch equals TRUE, a list element must be an exact match to specified value.
//Else, the specified value can be within a list element.
//Returns: The number of instances that a list element equals sValue.
int ListValueCount(string sList, string sValue, int nExactMatch=TRUE, int nCaseSensitive=TRUE, string sDelimiters=",");
//Descrption: Determines the index of all list elements that contain the sSubString.
//If nCaseSensitive equals TRUE, the result will consider case in the search.
//If nExactMatch equals TRUE, a list element must equal the sSubString to be counted.
//If the sSubString is within the list element and nExactMatch equals FALSE,
//the list element is considered a match.
//Returns: Comma separated list of index values of the list elements that contains or
//is equal to the sSubstring.
//If not found, returns an empty string.
string ListFind(string sList, string sSubString, int nExactMatch=TRUE, int nCaseSensitive=TRUE, string sDelimiters=",");
Version 1.03 - This ERF contains a single file containing the 3 String functions and 13 List functions. The most recent addition to the library is ListCompare. This new function compares two lists by method of "AND", "OR" or "XOR".
Posted by cricket at 2007-01-30 06:41:30 Voted 10.00 on 01/10/07
Correct me if I'm wrong, you are wanting a list function that performs an element override. So this 1 function could do the job of :
ListSetAt(sList,1,"6",",");
ListSetAt(sList,4,"3",",");
ListSetAt(sList,5,"2",",");
ListSetAt(sList,6,"75",",");
I kind-of see the point for this type of function but currently we will have to table this as a future enhancement due to other scripting priorities we are trying to accomplish.
Thanks for the input and ideas. Keep them coming!!!
SilentCricket
Posted by Urlord at 2007-01-30 05:06:49 Voted 10.00 on 01/09/07
Can you elaborate on when and how such a function would be used? _________________________ Peace,
Posted by Vanes at 2007-01-30 04:46:06 Voted 9.25 on 01/22/07
What I meant with that was that you would be able to fill in greater parts of a pre-existing list with more ease.
Say there's a list "1,2,3,4,5,6,7,8,9,10"
You 'paste' a string "6,,,3,2,75" to the list and it shows up as :
"6,2,3,3,2,75,7,8,9,10"
Umm, if you catch my drift. :) _________________________ Logical arguments tend to favour those who have much faith vested in them. Often accompanied by an epic skill to resist the arguments against.
Posted by Vanes at 2007-01-30 04:40:15 Voted 9.25 on 01/22/07
How about a function that processes a string to a list ? Could be used to quickly set up a list without using the invidual functions in a loop as a bonus.
Something like : StringToList(string sString,string sList,string sDelimiters=","); _________________________ Logical arguments tend to favour those who have much faith vested in them. Often accompanied by an epic skill to resist the arguments against.
Posted by Urlord at 2007-01-26 12:06:45 Voted 10.00 on 01/09/07
The latest version 1.02 has been uploaded. It corrects the bug found by Vanes as well as the three new List Funcrions. _________________________ Peace,
Posted by cricket at 2007-01-25 16:35:45 Voted 10.00 on 01/10/07
-- Vanes --
Thank you kindly for finding that critter and you are right. I failed to notice how it simply stuck it on the front and not do a replace. I've updated the code on our side and the new code should be posted tomorrow.
Included with the new updated code will be 3 new LIST functions: ListContains, ListValueCount, & ListFind.
Thanks again for the help.
Posted by Vanes at 2007-01-22 15:44:15 Voted 9.25 on 01/22/07
I figured it out finally. Either it's a slight mistake on your part or something but this fixed it for me :
In the ListSetAt() function, near the end it checks "if(nIndex == 1)" and if it is, just adds to the beginning of the list. So I changed this to read :
Now it will delete the first element and add the requested one as the first element, like it should. (In my mind) _________________________ Logical arguments tend to favour those who have much faith vested in them. Often accompanied by an epic skill to resist the arguments against.
Posted by Vanes at 2007-01-22 14:42:39 Voted 9.25 on 01/22/07
I have but one problem with these list functions. Otherwise they're perfect !
If I want to add an element to the second place in the list for example, and the list for starters doesn't exist..how do I go about doing that ?
I'm trying to store a string to the first element and another to the second element and so on, and update them every once in a while. For some reason when I use 'ListSetAt' and select iIndex 1 for example, and the string is something like "0,1", it outputs it as "1,0,1" or something when I'd want it to make it "1,1". Aaghh, what am I doing wrong ?
I really like these list functions, don't get me wrong. :) _________________________ Logical arguments tend to favour those who have much faith vested in them. Often accompanied by an epic skill to resist the arguments against.
Posted by puket at 2007-01-15 12:31:12 Voted 9.00 on 01/15/07
Solid work, keep up the good work, go further. Vote 9 is ok for me.
Posted by cricket at 2007-01-10 11:11:02 Voted 10.00 on 01/10/07
These list functions are great. They allow so much flexibility in the data that I can store. Retrieving the data is so much easier, too.
Posted by Urlord at 2007-01-09 20:20:50 Voted 10.00 on 01/09/07
Fixed a bug in ListGetAt() that was causing some wierdness when the elements were different lengths.
Please download the latest version. _________________________ Peace,
Posted by Urlord at 2007-01-09 15:13:33 Voted 10.00 on 01/09/07
This is the most useful set of functions I have ever seen. The more I use them the more uses I find for them. ABSOLUTELY AWESOME!!! _________________________ Peace,
10 - A Masterpiece, Genuinely Groundbreaking 9 - Outstanding, a Must Have 8 - Excellent, Recommended to Anyone 7 - Very Good, Deserves a Look 6 - Good, Qualified Recommendation 5 - Fair, Solid yet Unremarkable 4 - Some Merit, Requires Improvements 3 - Poor Execution, Potential Unrealized 2 - Very Little Appeal 1 - Not Recommended to Anyone