C# Long Substring function
I have a string that "may" be longer than any simple int boundaries.
Currently, the string.substring function takes only int parameters as index and length which is not enough for me since i need long for the parameter value types.
Do you know any implementation of long substring func开发者_Go百科tion?
Or what do you recommend I do to solve this possible finding substring problem with very long string?
Thank you.
I have a string that "may" be longer than any simple int boundaries.
No, in .NET you won't have that problem. The System.String
class itself uses Int32
indexing and Length properties everywhere.
Maybe you will have a (char) array that's over 2GB but that is taken care of, you can use 'long` indexing.
Related question: What is the maximum possible length of a .NET string?
As the answer in the link Henk provides states, you cannot create an object of size greater than 2GB in .NET (64-bit also has this restriction).
Therefore you can't have a string that big no matter what. You will need to use some sort of streaming algorithm to find and isolate the data you are interested in.
As Henk Holterman said System.String uses int32 ....
But if needed to, use unsigned int which can go to 4.300 million: try uint.
uint stringLength = 4,294,967,295
though it doesnt go that much higher than the normal int
int -> -2,147,483,648 to 2,147,483,647 uint -> 0 to 4,294,967,295
Also, conventional substring algorithms might not work well on that scale (actually I do not know how .Substring works). You might want to take a look at this.
精彩评论