Click here to Skip to main content
15,887,027 members
Please Sign up or sign in to vote.
4.50/5 (2 votes)
See more:
I have to load a huge string from stream and access some data written in it. I use substring to access the data, but its to slow . Is there a faster way maybe to convert it char array or is there a way to extract the data directly from stream? Thanks in advance.
Posted
Updated 22-Feb-11 23:08pm
v2

No wonder it's slow, because you copy your original string over and over; and this is because strings are immutable.

Why, what's is that home-baked file format, so you need to read it in one string.

The best answer depends on your format. Basically, you should parse your sub-strings into list of strings as you read the file. Another option is to read all string at once and tokenize it using string.Split. Again, what delimiters to use totally depends on your format.

In all cases, you don't use the whole string or forget it after Split.

I'm not sure what way is faster, it depends on typical length of your tokens and total length. I don't think you should worry: it will be many time faster compared to what you tried.

—SA
 
Share this answer
 
v2
Comments
apaka 23-Feb-11 5:28am    
Basicly its a jass file . I need to find "SetMapName("mapname") and to extract mapname and so on.
Sergey Alexandrovich Kryukov 23-Feb-11 5:31am    
I'm not familiar with those. Try both ways, split first. If the file is not huge, will be fast enough.
--SA
apaka 23-Feb-11 6:17am    
I used the first way it helps a lot. From the whole file I was able to extract 10 needed lines and the use substring on them.
Sergey Alexandrovich Kryukov 23-Feb-11 15:01pm    
Even if you used some third method, I hope I gave you an idea where you performance leak is.
Thanks for accepting my Answer.
Good luck, call again.
--SA
How big are we talking about? I use a combination of IndexOf and Substring to great effect when parsing HTML returned from a web request. I can do a 280K file in a timely manner.

What kind of parsing needs to be done? Is the data in a predictable pattern? Can you use Split?
 
Share this answer
 
Comments
apaka 23-Feb-11 6:15am    
It's about 5-30K lines. Not predictable it's a programing language. Thanks anyway.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900