14,299,038 members
Rate this:
See more:
Hi, friends

I have one Problem
i wanna to split the sting

code:
``` Address[0] = "12345678901234567890201234567890123456789040123456789012345678906012345678901234567890801234567890123456789020123456789012345678904012345678901234567890601234567890123456789080";

int ee = Address[0].Length / 2;

its not working plz help me.....
Posted
Updated 31-Jan-12 20:28pm
v2

--SA

Not clear what is the expected result of splitting. And why this is a problem?
--SA
SathyaRaju 1-Feb-12 2:45am

i wanna to split every 40 char...like this
4444444444444444
4444444444444444
44444444444444444
Jyothikarthik_N 1-Feb-12 1:52am

Not clear. Please explain what you're trying to achieve!
SathyaRaju 1-Feb-12 2:45am

i wanna to split every 40 char...like this
4444444444444444
4444444444444444
44444444444444444
Jyothikarthik_N 1-Feb-12 4:10am

Ok, Do check out the solution I've provided.
Kim Togo 1-Feb-12 2:14am

You want to split the string for every 40's chars?
SathyaRaju 1-Feb-12 2:45am

i wanna to split every 40 char...like this
4444444444444444
4444444444444444
44444444444444444
Tech Code Freak 1-Feb-12 2:58am

And maximum, how long can your string be?

Rate this:

Solution 1

[EDIT]
Now, after knowing your actual requirement, I have developed this short and sweet code:
```string Addresses = string.Empty;
int stInd = 0, cnt = Address[0].Length / 40;
{
for (int i = 0; i <= cnt; i++)
{
stInd = i * 40;
if (i == cnt)
else
}
}
else

[EDIT]
v6
nevin 2011 1-Feb-12 5:58am

Great solution!

My 5!
SathyaRaju 2-Feb-12 1:14am

thanks .....its works really super....
Amir Mahfoozi 12-Feb-12 2:16am

+5
Rate this:

Solution 2

Use this function
```public string stringBreak(string objstring, int intLength)
{
string strChr = objstring;
string objFinalString = "";
if (strChr.Length > intLength)
{
char[] sep = { ' ' };
string[] strChrArray = strChr.Split(sep);
int objcount1 = 0;
while (objcount1 < strChrArray.Length)
{
if (strChrArray[objcount1].Length > intLength)
{
int i = 0;
string obj = "";
int objcount = 0;
objcount = 0;
while (objcount < strChrArray[objcount1].Length)
{
if (objcount > strChrArray[objcount1].Length)
{
obj = strChrArray[objcount1].Substring(objcount - intLength);
}
else
{
try
{
obj = strChrArray[objcount1].Substring(objcount, intLength);
}
catch (Exception ex)
{

obj = strChrArray[objcount1].Substring(objcount);
}
}
objFinalString = objFinalString + "" + obj + " <br> ";
objcount = objcount + intLength;
}
}
else
{
objFinalString = objFinalString + " " + strChrArray[objcount1];
}
objcount1 = objcount1 + 1;
}
strChr = objFinalString;
}
return strChr;
}```
SathyaRaju 1-Feb-12 3:00am

ok thanks Anuja ...its work
Anuja Pawar Indore 1-Feb-12 3:01am

You are welcome :)
SathyaRaju 1-Feb-12 5:09am

i have one problem ...
if i give the space its not work.....format is changed
Rate this:

Solution 3

Hi,

I can see that guys are already solved your problem but here is another one solution...
Try this simple extension method...
```public static class ExtensionMethods
{
public static IEnumerable<string> Split(this string str, int chunkSize)
{
return Enumerable.Range(0, str.Length / chunkSize).Select(i => str.Substring(i * chunkSize, chunkSize));
}
}</string>```

Usage:
```string addressString = "12345678901234567890201234567890123456789040123456789012345678906012345678901234567890801234567890123456789020123456789012345678904012345678901234567890601234567890123456789080";

{
}```
Rate this:

Solution 4

Here's an even simpler solution :)

```public string stringBreak(string objstring, int intLength)
{
return System.Text.RegularExpressions.Regex.Replace(objstring, "[\\d\\s]{" + intLength + "}", "\$&<br>");
}```

v5
SathyaRaju 1-Feb-12 5:25am

i have one problem ...
if i give the space its not work.....format is changed
Jyothikarthik_N 1-Feb-12 5:26am

Space is given where? can you give an example?
SathyaRaju 1-Feb-12 5:35am

string Address = "1234567890123 4567890201234567gdfghfg gggggggggggggggg gggggggggggggggggg gggggggggggggggggdfdf");

this type its not working .....
Jyothikarthik_N 1-Feb-12 5:40am

I've updated the solution, that should solve I guess.
SathyaRaju 1-Feb-12 5:42am

thanks....
me too try to solve the problem....
Tech Code Freak 1-Feb-12 5:45am

Why aren't you trying my solution?
If you have tried it, then give me some reply!
SathyaRaju 1-Feb-12 7:37am

thanks ...but string length is multiplied.....
Tech Code Freak 2-Feb-12 0:56am

Now I have edited it. Check my solution(Solution 1) again.