StringReader

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

    StringReader

    I am using stringreader to repeat through each line of a
    file ,but my string reader is clubbing 4 to 5 lines as
    single line at few places, what could be the problem?

    Please send me the suggestions

    Thank you
  • Miha Markic

    #2
    Re: StringReader

    Hi Vannela,

    Are you shure that file lines are delimited with \r, \n, or \r\n?

    --
    Miha Markic - RightHand .NET consulting & software development
    miha at rthand com

    "Vannela" <anonymous@disc ussions.microso ft.com> wrote in message
    news:075301c3b8 02$be5ae860$a10 1280a@phx.gbl.. .[color=blue]
    > I am using stringreader to repeat through each line of a
    > file ,but my string reader is clubbing 4 to 5 lines as
    > single line at few places, what could be the problem?
    >
    > Please send me the suggestions
    >
    > Thank you[/color]


    Comment

    • Jon Skeet [C# MVP]

      #3
      Re: StringReader

      Vannela <anonymous@disc ussions.microso ft.com> wrote:[color=blue]
      > I am using stringreader to repeat through each line of a
      > file ,but my string reader is clubbing 4 to 5 lines as
      > single line at few places, what could be the problem?[/color]

      Well, the problem is probably in your code. Please post a short but
      complete example program which demonstrates the problem - see
      http://www.pobox.com/~skeet/csharp/complete.html for what I mean by
      that.

      --
      Jon Skeet - <skeet@pobox.co m>
      Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

      If replying to the group, please do not mail me too

      Comment

      • Vannela

        #4
        Re: StringReader

        source string conatins this code:

        type cb_ok from commandbutton within
        w_cd_review_reg ulatory_approva l
        int X=933
        int Y=924
        int Width=302
        int Height=108
        int TabOrder=40
        boolean Enabled=false
        boolean BringToTop=true
        string Text="Approve"
        boolean Default=true
        int TextSize=-10
        int Weight=400
        string FaceName="Arial "
        FontFamily FontFamily=Swis s!
        FontPitch FontPitch=Varia ble!
        end type

        event
        clicked;//*************** *************** *************** ****
        *************** **
        STRING l_Message[]
        IF fw_Save() <> c_Success THEN
        RETURN
        END IF


        //---------------------------------------------------------
        ---------
        // Close the window.
        //---------------------------------------------------------
        ---------

        Close(PARENT)

        //*************** ******** End of Script ************

        end event

        type cb_cancel from commandbutton within
        w_cd_review_reg ulatory_approva l
        int X=1344
        int Y=924
        int Width=302
        int Height=108
        int TabOrder=50
        boolean BringToTop=true
        string Text="Cancel"
        boolean Cancel=true
        int TextSize=-10
        int Weight=400
        string FaceName="Arial "
        FontFamily FontFamily=Swis s!
        FontPitch FontPitch=Varia ble!
        end type

        event
        clicked;//*************** *************** *************** ****
        *************** **
        i_SaveOnClose = c_CloseNoSave

        Close(PARENT)

        //*************** ******** End of Script
        *************** *************

        end event

        I want to get the string from the match :TYPE (followed by
        some word) FROM (followed by some word) till i encounter
        another such match. But my problem is in the above source
        string which i have given it is matching the below whole
        thing as a single line in this way that too only at few
        places and with type of code ( as different input it is
        working fine) what could be the problem?


        Close(PARENT) //*************** ******** End of Script
        *************** ************* end event type cb_cancel
        from commandbutton within w_cd_review_reg ulatory_approva l
        int X=1344 int Y=924 int Width=302 int Height=108 int
        TabOrder=50 boolean BringToTop=true string Text="Cancel"
        boolean Cancel=true int TextSize=-10 int Weight=400
        string FaceName="Arial " FontFamily FontFamily=Swis s!
        FontPitch FontPitch=Varia ble! end type event
        clicked;//*************** *************** *************** ****
        *************** **



        int v_flag=0;
        StringReader v_rdr=new StringReader(so urce);
        for(string v_Wline =v_rdr.ReadLine ();v_Wline!
        =null;v_Wline=v _rdr.ReadLine() )
        {
        while(v_flag==0 )
        {

        if(Regex.IsMatc h
        (v_Wline,@"type \s+\w+\s+from\s +"+@"\w+",Regex Options.Ignore
        Case))
        {
        Match v_match =Regex.Match
        (v_Wline,@"\w+\ s+from\s+",Rege xOptions.Ignore Case);

        v_tempcode=null ;
        do
        {
        v_tempcode+=v_W line+"\n";
        v_Wline=v_rdr.R eadLine();

        if(v_Wline==nul l)
        {
        v_flag=1;
        break;
        }
        }while(!Regex.I sMatch
        (v_Wline,@"type \s+\w+\s+from\s +",RegexOptions .IgnoreCase));

        }
        }

        [color=blue]
        >-----Original Message-----
        >Vannela <anonymous@disc ussions.microso ft.com> wrote:[color=green]
        >> I am using stringreader to repeat through each line of[/color][/color]
        a[color=blue][color=green]
        >> file ,but my string reader is clubbing 4 to 5 lines as
        >> single line at few places, what could be the problem?[/color]
        >
        >Well, the problem is probably in your code. Please post a[/color]
        short but[color=blue]
        >complete example program which demonstrates the problem -[/color]
        see[color=blue]
        >http://www.pobox.com/~skeet/csharp/complete.html for what[/color]
        I mean by[color=blue]
        >that.
        >
        >--
        >Jon Skeet - <skeet@pobox.co m>
        >http://www.pobox.com/~skeet
        >If replying to the group, please do not mail me too
        >.
        >[/color]

        Comment

        • Jon Skeet [C# MVP]

          #5
          Re: StringReader

          Vannela <anonymous@disc ussions.microso ft.com> wrote:

          <snip>
          [color=blue]
          > I want to get the string from the match :TYPE (followed by
          > some word) FROM (followed by some word) till i encounter
          > another such match. But my problem is in the above source
          > string which i have given it is matching the below whole
          > thing as a single line in this way that too only at few
          > places and with type of code ( as different input it is
          > working fine) what could be the problem?[/color]

          I suspect your problem is that you're building up the string with just
          "\n"s in instead of full carriage return / line feeds ("\r\n"). I would
          also suggest using a StringBuilder instead of string concatenation.

          However, you should really go through it line by line with the
          debugger, and find out what lines are being *read* each time, to see
          whether StringReader really is reading more than one line unexpectedly.
          Does your input file perhaps contain a mixture of "\n" and "\r\n"
          linebreaks? That shouldn't confuse StringReader, but it might be worht
          investigating.

          --
          Jon Skeet - <skeet@pobox.co m>
          Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

          If replying to the group, please do not mail me too

          Comment

          Working...