Introduction
Intersystem Cache's $piece functionality is replicated in C#.NET
Background
$piece in Cache Objectscript returns a specific piece of a string based on a specified delimiter. It can also return a range of pieces, as well as multiple pieces from a single string, based on multiple delimiters. This functionality is replicated in C#.NET. This will be useful when there is a need for Inter operability between cache and .NET
The code
Code:
public string piecedString(string instr,int delimiter, int piece)
{
string[] splitinstr = instr.Split((char)delimiter);
string returnpiece = splitinstr[piece - 1].ToString();
return returnpiece;
}
public string piecedString(string instr, int delimiter, int start,int stop)
{
string[] splitinstr = instr.Split((char)delimiter);
StringBuilder returnpiece = new StringBuilder();
for (int i = start; i <= stop; i++)
{
returnpiece.Append(splitinstr[i - 1].ToString());
if (i != stop)
{
returnpiece.Append((char)delimiter);
}
}
return returnpiece.ToString();
}

