Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to PadRight to Work

Status
Not open for further replies.

bruce282

Programmer
Jan 26, 2007
8
US
I'm trying to incorporate .PadRight into my program. I want to make sure each text line is 574 bytes long. I've tried several things, including some suggestions from here. Below is my code. I get the following error when I uncomment the bolded line below, but the console.write works. I'm sure this is something small or stupid. Also please excuse all the extraneous garbage in the pgm right now.

Error 1 'string' does not contain a definition for 'padright' and no extension method 'padright' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)

Code:
using System.IO;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace ReformatDEERs
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            
            InitializeComponent();
        }

        public void reformatButton_Click(object sender, EventArgs e)
        {
            string fileLine = "";
            string newLine ="";
            long all_records=0;
            int shorty_records=0;
            ulong[] rec_len = new ulong[574];

            if (openFileDialog1.ShowDialog()==DialogResult.OK)
            {
                string name= openFileDialog1.FileName;
                FileInfo fileI = new FileInfo(name);
                // StreamReader fileSR = new StreamReader(file.opentext(name));
                StreamReader fileSR = new StreamReader(@"g:\bruce\f\deers\a.txt");
                fileLine = fileSR.ReadLine();
                while(/*fileLine!=null*/ all_records < 300)
                {
                    if (fileLine.Length < 574)
                    {
                        shorty_records = shorty_records +1;
                        Console.Write(fileLine.PadRight(600));
              [b]   //  newLine = fileLine.padright(574);
        [/b]        }
                    all_records += 1;
                    rec_len[(fileLine.Length-1)] += 1;
                    fileLine=fileSR.ReadLine();
                }
            }
            MessageBox.Show("Count = " + all_records,"ALL RECORDS");
            MessageBox.Show("Shorties = " + shorty_records,"Short Dudes");
        }
              
        
    }
}
 
1. you need to properly dispose of the reader when you are done
Code:
using(var reader = new StreamReader(path))
{
  do someting with reader.
}
2. if you are going to read each line then you need to iterate the lines
Code:
while(reader.EndOfStream == false)
{
   var line = reader.ReadLine();
   do something with line
}
putting it all together
Code:
using(var reader = new StreamReader(path))
{
   while(reader.EndOfStream == false)
   {
      var line = reader.ReadLine();
      do something with line
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
bruce282,
Is the code you have here in your post the same EXACT code you have in your program?????? IF it IS the same excat code, take a look at your padright. It shoulbe PadRight.

Remember, c# is case sensitive. I tried your sample line and got the identical error message. Again, remember, c# is CASE SENSITIVE. And the intellisense will NOT correct it for you, like it does in vb.net.
 
That was it. I have to admit I got used to VB correcting the spelling for me.

Thanks a bunch.

Bruce
 
Bruce,
No problem. I've done some of the same things. Soon, you'll learn to check the case sensitivity when you see the error msg you saw.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top