Spliting Large String

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • - Steve -

    Spliting Large String

    I have a string that contains something along the lines of this:

    This is a body of an e-mail message. I have no idea how long it goes, how
    it ends, etc.

    ------ Do not modify below ------
    <query>filename .csv</query>

    I need to split the string into two parts. The body of the message part,
    and I need to extract the filename between the <query> brackets. What's the
    best way to go about this? I was thinking I could find the index of "------
    Do not modify below ------" but that seems like a flakey way to do it.


  • Daniel Billingsley

    #2
    Re: Spliting Large String

    Well, you could us a regex, but that seems like unnecessary overkill. I
    don't know what you mean exactly by "flakey", but using IndexOf to find the
    <query> and the </query> and then Substring to get the part in between seems
    straightforward enough to me. I would think any alternative you devised
    would look just as "flakey" as IndexOf.


    "- Steve -" <sevans@foundat ion.sdsu.edu> wrote in message
    news:OiVrRACoEH A.1668@TK2MSFTN GP14.phx.gbl...[color=blue]
    > I have a string that contains something along the lines of this:
    >
    > This is a body of an e-mail message. I have no idea how long it goes, how
    > it ends, etc.
    >
    > ------ Do not modify below ------
    > <query>filename .csv</query>
    >
    > I need to split the string into two parts. The body of the message part,
    > and I need to extract the filename between the <query> brackets. What's[/color]
    the[color=blue]
    > best way to go about this? I was thinking I could find the index of[/color]
    "------[color=blue]
    > Do not modify below ------" but that seems like a flakey way to do it.
    >
    >[/color]


    Comment

    • Tom Clement

      #3
      Re: Spliting Large String

      If you're only searching it once, I don't see anything wrong with using
      IndexOf(). You might consider using regular expressions if you expect to
      search more than once.
      Tom Clement
      Apptero, Inc.


      "- Steve -" <sevans@foundat ion.sdsu.edu> wrote in message
      news:OiVrRACoEH A.1668@TK2MSFTN GP14.phx.gbl...[color=blue]
      >I have a string that contains something along the lines of this:
      >
      > This is a body of an e-mail message. I have no idea how long it goes, how
      > it ends, etc.
      >
      > ------ Do not modify below ------
      > <query>filename .csv</query>
      >
      > I need to split the string into two parts. The body of the message part,
      > and I need to extract the filename between the <query> brackets. What's
      > the best way to go about this? I was thinking I could find the index of
      > "------ Do not modify below ------" but that seems like a flakey way to
      > do it.
      >[/color]


      Comment

      • Phil Jenson

        #4
        Re: Spliting Large String

        Steve,

        If you want to allow for the unlikely eventuality that your body also
        contains the mark

        "------ Do not modify below ------"

        (ie. it occurs twice) then use the method LastIndexOf

        Phil...


        "- Steve -" <sevans@foundat ion.sdsu.edu> wrote in message
        news:OiVrRACoEH A.1668@TK2MSFTN GP14.phx.gbl...[color=blue]
        >I have a string that contains something along the lines of this:
        >
        > This is a body of an e-mail message. I have no idea how long it goes, how
        > it ends, etc.
        >
        > ------ Do not modify below ------
        > <query>filename .csv</query>
        >
        > I need to split the string into two parts. The body of the message part,
        > and I need to extract the filename between the <query> brackets. What's
        > the best way to go about this? I was thinking I could find the index of
        > "------ Do not modify below ------" but that seems like a flakey way to
        > do it.
        >[/color]


        Comment

        Working...