I needed a string replace method in CScript. There wasn't one available, so I made my own. I'm providing it to you under a Creative Commons Attribution 3.0 Unported License.
The code is below, as well as attached (with usage info, copyright notice and proper indenting).
- Code: Select all
function StringIndexOf(string source, string match) integer
{
integer output := -1
integer sourceLen := StringLength( source )
integer matchLen := StringLength( match )
integer i
integer n := sourceLen - matchLen
for i from 0 to n
{
string outputSubstring := GetSubstring( source, i, matchLen )
integer x := CompareString( outputSubstring, match)
if( x = 0 )
{
return i
}
}
return -1
}
You might want to add it to StringFuncs.cscript in your next release.
