Go4Expert (http://www.go4expert.com/)
-   ASP.NET (http://www.go4expert.com/articles/asp-net-tutorials/)
-   -   $piece Function Replicated In .NET (http://www.go4expert.com/articles/piece-function-replicated-net-t19104/)

naimish 20Aug2009 15:45

$piece Function Replicated In .NET


Intersystem Cache's $piece functionality is replicated in C#.NET


$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


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)
            return returnpiece.ToString();

shabbir 2Sep2009 18:56

Re: $piece Function Replicated In .NET
Nomination for Article of the month - Aug 2009 Started.

All times are GMT +5.5. The time now is 02:02.