Regular Expression Help...Line Break

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jsummit@gmail.com

    #1

    Regular Expression Help...Line Break

    I'm trying to parse a rather large string from a .txt file that breaks
    into 2 lines ( the string is a fixed-length string reaching 6694
    characters) into a dataset using VB.net. The issues that I am having is
    with the line breaks. I am able to parse the string into the dataset up
    in till the line breaks. My pattern is as follows..
    "^(?<n0>.{1})(? <n1>.{8})(?<n2> .{2})..... (?<n404>.{2})$"
    My code is as follows:

    Dim re as New Regex(patern)
    Dim ma as Match = re.Match(sr.Rea dLine(), RegexOptions.Mu ltiLine)
    Do while
    ma.Groups("n" & i & "").Value.ToStr ing
    Loop

    My issue is when I hit a line break in the txt file. The reason the
    string breaks is that it is so long that it reaches the max places of
    the txt file and has to continue on the next line. The beginning of a
    new line then begins on the next line .
    Example:
    I33445 89 u000x00000 900000 x00000 ....... (on and on until the
    max length of a txt file).......000 0 00000000 (End of Txt file)
    TOWN88989 000000000000 909 (end of String)
    NEW Line Starts Here.

    I have tried different options with RegexOptions but to no avail.

    Thank you for your time.

  • Andrew Morton

    #2
    Re: Regular Expression Help...Line Break

    jsummit@gmail.c om wrote:[color=blue]
    > I'm trying to parse a rather large string from a .txt file that breaks
    > into 2 lines ( the string is a fixed-length string reaching 6694
    > characters) into a dataset using VB.net. The issues that I am having
    > is with the line breaks.[/color]

    How about removing all the line breaks first?

    Andrew


    Comment

    • jsummit@gmail.com

      #3
      Re: Regular Expression Help...Line Break

      I have tried that - It's not an option. The string is so large that it
      extends the whole length of the txt file and then some. I didn't think
      there was an end or a line break in a txt file. I though you would be
      able to extend as far right as you would like. Not so.

      Thanks for you idea.

      Jim

      Comment

      • Andrew Morton

        #4
        Re: Regular Expression Help...Line Break

        jsummit@gmail.c om wrote:[color=blue]
        > I have tried that - It's not an option. The string is so large that it
        > extends the whole length of the txt file and then some.[/color]

        It cannot. Past the end of the file there is nothing. Or do you mean there
        is an EOF character in there?
        [color=blue]
        > I didn't think
        > there was an end or a line break in a txt file.[/color]

        Any byte can be in a text file; text file means only that it is meant to be
        human-readable with minimal processing (e.g. tab characters).

        Look at the supposedly text file in a hex editor. Do not trust Notepad.
        [color=blue]
        > I though you would be
        > able to extend as far right as you would like. Not so.[/color]

        That must be a limitation of the program displaying/writing the text file.
        [color=blue]
        > ( the string is a fixed-length string reaching 6694 characters)[/color]

        That's a tiny string compared to the limit of something like 2^31-1 chars.
        When you say "reaching 6694 characters", do you mean it is /always/ 6694
        chars, and, if so, does that mean that each field is of a fixed width too?
        In that case, you could just extract each substring with
        System.String.S ubtring(int32, int32).

        Andrew


        Comment

        • jsummit@gmail.com

          #5
          Re: Regular Expression Help...Line Break

          Both of you questions are yes. Is /always/6694 char, and each field is
          a fixed length. Although each field's length is different. I have been
          reading the file thought Note Tab and probably why the break is at the
          same spot.
          I'm going to look into the system.string.s ubstring. That may work. If
          the a string can stretch 2^31-1 char in a txt file, then how come I'm
          having issues with my short string breaking? I have no control on how
          the string is extracted out and dumped into the txt file. The file I
          have received is a .txt file.
          Thanks again for you help.

          -Jim

          Comment

          • jsummit@gmail.com

            #6
            Re: Regular Expression Help...Line Break

            Which object would you sugest to use? StreamReader, stringReader?
            TextReader? In order to use the subString and write out the string
            values to a ds. I was using a StreamReader.

            Thanks

            Comment

            • Andrew Morton

              #7
              Re: Regular Expression Help...Line Break

              jsummit@gmail.c om wrote:[color=blue]
              > Which object would you sugest to use? StreamReader, stringReader?
              > TextReader?[/color]

              See the help for StreamReader and for StringReader to determine the
              appropriate choice.

              Andrew


              Comment

              • Andrew Morton

                #8
                Re: Regular Expression Help...Line Break

                jsummit@gmail.c om wrote:[color=blue]
                > I'm going to look into the system.string.s ubstring. That may work. If
                > the a string can stretch 2^31-1 char in a txt file, then how come I'm
                > having issues with my short string breaking? I have no control on how
                > the string is extracted out and dumped into the txt file. The file I
                > have received is a .txt file.[/color]

                Have you looked at the file in a hex editor to see if there are any
                unexpected characters in it? The fact it has an extension of .txt is
                irrelevant.

                In the case of what I think your file looks like, unexpected characters
                would be anything with a decimal value in the range 0-31. Possibly you would
                find 13,10 (CRLF) at the end.

                Note that files and strings are not connected. The maximum possible size of
                a file (disregarding hardware) is determined by the OS.

                Andrew


                Comment

                • jsummit@gmail.com

                  #9
                  Re: Regular Expression Help...Line Break

                  The Hexadecimal value for the line break in the txt file is 30 and the
                  decial value is 0. Are 13, 10 values you mentond are decimal values or
                  hexadecimal values?

                  Thanks

                  Comment

                  • Andrew Morton

                    #10
                    Re: Regular Expression Help...Line Break

                    jsummit@gmail.c om wrote:[color=blue]
                    > The Hexadecimal value for the line break in the txt file is 30 and the
                    > decial value is 0.[/color]

                    Three-zero in hex is the /character/ 0, i.e. zero, in ASCII.
                    30(hex), sometimes written 0x30, or &H30 in VB, has a decimal value of 48.

                    I really don't think 0 is being used as a line break.
                    [color=blue]
                    > Are 13, 10 values you mentond are decimal values or
                    > hexadecimal values?[/color]

                    Decimal.

                    ASCII Chart - Table of ASCII characters and equivalents. Also Q&A about ASCII, conversion from decimal to hex, and other references


                    Andrew


                    Comment

                    Working...