1. We have moved from vBulletin to XenForo and you are viewing the site in the middle of the move. Though the functional aspect of everything is working fine, we are still working on other changes including the new design on Xenforo.
    Dismiss Notice

$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,046
    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,276
    Likes Received:
    364
    Trophy Points:
    83

Share This Page