Connecting Tech Pros Worldwide Forums | Help | Site Map

divide substring

Newbie
 
Join Date: Mar 2009
Posts: 12
#1: Jul 3 '09
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's Avatar
Moderator
 
Join Date: Mar 2008
Location: Arizona, USA
Posts: 1,783
#2: Jul 3 '09

re: divide substring


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.

Expand|Select|Wrap|Line Numbers
  1. string bob = "asd.wetr.wrt6y.sdfg.edgh";
  2. 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.
  3. string Part1 = bobArray[0] + bobArray[1] + bobArray[2] + bobArray[3];// brute force but meant for demonstrative purpose
  4. string Part2 = bobArray[4];
  5.  
Reply