[RESOLVED] String IndexOf and Remove VS Regex
Hi!
I have a string with 60000+ characters. I look for informations inside the string in a sequentially order. Every time I found a information I delete whatever is behind that information. In other words I reduce the size of the string every time I find something, and I do this using IndexOf and Remove, much like this:
vb.net Code:
Str = Str.Remove(0, Str.IndexOf("MyInfo"))
This can be quite heavy on the processor. So my question is it faster to look the informations using Regex or it would be about the same?
Re: String IndexOf and Remove VS Regex
Hey,
In terms of string manipulation, Regular Expressions are about as optimised as you can get, so I would suggest that you will see a performance improvement in using Regex.
Give it a try and see.
You could use the StopWatch Class to get some timings to compare both methods.
Gary
Re: String IndexOf and Remove VS Regex
Just changed everything to Regex.
Re: [RESOLVED] String IndexOf and Remove VS Regex
Hey,
Good man!! I like Regex :)
Gary
Re: [RESOLVED] String IndexOf and Remove VS Regex
Now, so do I! Regex rocks!!
Re: [RESOLVED] String IndexOf and Remove VS Regex
One thing that I will point out is a very nice little application for creating Regular Expressions, it's called RegExBuddy, you can find a link to it in my signature. It isn't free, but there is a trial version to see if you like it.
Also, if you haven't found it yet, have a look at RegExLib, also in my signature.
Gary