$piece Function Replicated In .NET

Discussion in 'ASP.NET' started by naimish, Aug 20, 2009.

  1. naimish

    naimish New Member

    Joined:
    Jun 29, 2009
    Messages:
    1,043
    Likes Received:
    18
    Trophy Points:
    0
    Occupation:
    Software Engineer
    Location:
    On Earth

    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();
            }
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,336
    Likes Received:
    377
    Trophy Points:
    83

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice