-1
ちょっとの合計行を表示するWindowsアプリケーションを作成したい、空白行とコメント行。私は合計行を計算することができます。空白行とコメント行のロジックを手助けすることができますか?C#WindowsアプリケーションLOC_Counter
私は、すなわち.htmlを、.cssの、.csファイル任意のファイルのために、コードの行数をカウントしたい、など
また、私は結果はエクセルファイルにエクスポートしたい可能であれば!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
namespace Line_Counter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
textbox1.Clear();
textbox2.Clear();
if (ofd.ShowDialog() == DialogResult.OK)
{
string strFilename = ofd.FileName;
textbox1.Text = Path.GetFileName(strFilename);
StreamReader sr = File.OpenText(strFilename);
int nLineCount = 0;
while (sr.ReadLine() != null)
{
nLineCount++;
}
textbox1.Text = nLineCount.ToString("0,0");
sr.Close();
}
}
private void txtFileName_TextChanged(object sender, EventArgs e)
{
}
private void button2_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
私は、空白行の数を表示する必要がある複数のテキストボックスをしたい行をコメントし、最終的に合計数(すなわちなしを差し引く。空白行のとコメント行数の合計からの行数)
可能な場合は、1つのボタンオールまたはすべてのボタンをクリックします。 enter image description here
あなたは何を試しましたか、正確にどこにいるのですか?あなたが投稿したコードは全体の行数をカウントします... – bassfader
はい、私は空白行とコメント行を数える必要があります。 ------------------------------------------------- ------------------------------------------ if(str!= null && str.Length> 0 &&(str.Length> 2 && str.Substring(0、2)!= "//")&&(str.Length> 3 && str.Substring(0、4)!= "<! - - ")) 私はこのロジックを使用していますが、button_clickを使ってテキストボックスに表示する方法については助けが必要です –