Results 1 to 6 of 6

Thread: [RESOLVED] String IndexOf and Remove VS Regex

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Resolved [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:
    1. 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?
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  2. #2
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

  3. #3

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: String IndexOf and Remove VS Regex

    Just changed everything to Regex.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  4. #4
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    Re: [RESOLVED] String IndexOf and Remove VS Regex

    Hey,

    Good man!! I like Regex

    Gary

  5. #5

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [RESOLVED] String IndexOf and Remove VS Regex

    Now, so do I! Regex rocks!!
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  6. #6
    PowerPoster gep13's Avatar
    Join Date
    Nov 2004
    Location
    The Granite City
    Posts
    21,963

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width