divide substring

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • punjabplus
    New Member
    • Mar 2009
    • 12

    #1

    divide substring

    hi
    i have long text of around 1000 words i want this text to divide in two text . and i want to pick first text from 5th (.) dot coming in the text. how can i do this i know the use of substring and also split function in asp.net . but problum is that how can i pick from 5th(.) dot coming in the text please help me thanks in advance.
  • tlhintoq
    Recognized Expert Specialist
    • Mar 2008
    • 3532

    #2
    You could split it into an array of many instead of just two, splitting on all the periods. Then combine the first 4 back into 1 string, and all the remainder into another.

    Code:
    string bob = "asd.wetr.wrt6y.sdfg.edgh";
    string[] bobArray = bob.Split(new char[]{'.'},5);//2nd param is max number of splits so this will make 4 little parts at each period, then leave the rest as the 5th big part.
    string Part1 = bobArray[0] + bobArray[1] + bobArray[2] + bobArray[3];// brute force but meant for demonstrative purpose
    string Part2 = bobArray[4];

    Comment

    Working...