i'm having a string(MyString) of length 9700000(approximately). and a for loop to get substring from this String
like
for(int i=0;i<MyString.Length;i+=1000)
{
String SStr=MyString.Substring(i,1000);
}
in this loop i'm geting an exception like OutOfMemory Exception. But if i assign the MyString to a temporary string and using it(temporary string) instead of MyString in the for loop,then its working fine.
What will be the reason for this. And how its stored in memory?
EDIT : I used StringBuilder too
Like
for(int i=0;i<MyStringBuilder.Length;i+=1000)
{
String SStr=MyStringBuilder.ToString().Substring(i,1000);
}
But the same thing is happening.
Edit MyString and MyStringBuilder are Global Variables