$piece Function Replicated In .NET

naimish's Avatar author of $piece Function Replicated In .NET
This is an article on $piece Function Replicated In .NET in ASP.NET.
Rated 5.00 By 1 users

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();
        }
Go4Expert Founder
2Sep2009,18:56   #2
shabbir's Avatar
Nomination for Article of the month - Aug 2009 Started.