HI all,
Here i am retrieving mobile numbers from database like
919849098490(means 12 digit).And i am getting hundreds of numbers to a
variable.
so i need to divide those numbers into 100 numbers into a string with commas.
means
if i have 245 mobile numbers then i need to divide those numbers to
three strings like first 100 numbers to str1,next hundred numbers to
str2 and remaining 45 numbers to str3.
above situation is an example.
if i have mobile numbers like 850 then i have 9 string variables.
I want in a line(12 digit numbers string) also
appended a comma for every 12 digit number except before first number
and after last number.
Means 919849098490,919849098490,919849098490 here three 12 digit numbers are there and separated with two commas only.
i want like
str1 =919849098490,919849098490,919849098490
thank you.
Loading
Nipun TomarPosted Dec 9, 2008, 5:50 AM
hope this should help..
//labelInput has the mobile number string
labelLength.Text = labelInput.Text.Length.ToString();//suppose length of the required string is 120 instead of 100 characters
int dividers=labelInput.Text.Length/120;
//if the end of string is less than 120 characters
if (labelInput.Text.Length % 120 > 0)
dividers += 1;
//create an array to split and hold the actual string
string[] str= new string[dividers];
for (int i = 0; i < dividers; i++)
{
//if last array element has less than 120 characters
if ((i==(dividers-1)) && (labelInput.Text.Length % 120 > 0))
str[i] = labelInput.Text.Substring(i * 120, labelInput.Text.Length % 120);
else
str[i] = labelInput.Text.Substring(i * 120, 120);
//insert ,
for (int j = 1; j < (labelInput.Text.Length % 120/12); j++)
str[i] = str[i].Insert(j*12+j-1, ",");
richTextBox1.Text += str[i] + "\n";
}