0% found this document useful (0 votes)
4 views3 pages

Cau1 FileExamples

The document contains two examples of C# programs. The first program splits full names into last name, middle name(s), and first name, writing the results to a new file. The second program checks the validity of passwords based on specific criteria and outputs the results to a separate file.

Uploaded by

minhdongtran240
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views3 pages

Cau1 FileExamples

The document contains two examples of C# programs. The first program splits full names into last name, middle name(s), and first name, writing the results to a new file. The second program checks the validity of passwords based on specific criteria and outputs the results to a separate file.

Uploaded by

minhdongtran240
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Câu 1 - Tập tin (Ví dụ 1 & Ví dụ 2)

Ví dụ 1: Tách Họ - Tên lót - Tên


using System;
using [Link];

class Program
{
static void Main()
{
string inputPath = "[Link]";
string outputPath = "[Link]";

string[] lines = [Link](inputPath);

using (StreamWriter writer = new StreamWriter(outputPath))


{
foreach (string line in lines)
{
string[] parts = [Link]().Split(' ');

string ho = parts[0];
string ten = parts[[Link] - 1];

string tenLot = "";


for (int i = 1; i < [Link] - 1; i++)
{
tenLot += parts[i] + " ";
}
tenLot = [Link]();

[Link](line);
[Link]("- Ho: " + ho);
[Link]("- Ten lot: " + tenLot);
[Link]("- Ten: " + ten);
}
}

[Link]("Da xu ly xong Names!");


}
}

Ví dụ 2: Kiểm tra Password


using System;
using [Link];
class Program
{
static bool KiemTraPassword(string s)
{
if ([Link] < 8)
return false;

bool coChuThuong = false;


bool coChuHoa = false;
bool coSo = false;

foreach (char c in s)
{
if ([Link](c)) coChuThuong = true;
if ([Link](c)) coChuHoa = true;
if ([Link](c)) coSo = true;
}

return coChuThuong && coChuHoa && coSo;


}

static void Main()


{
string path;

while (true)
{
[Link]("Nhap duong dan file [Link]: ");
path = [Link]();

if ([Link](path))
break;
else
[Link]("File not found!");
}

string[] lines = [Link](path);

string outputPath = [Link](


[Link](path),
"[Link]"
);

using (StreamWriter writer = new StreamWriter(outputPath))


{
foreach (string line in lines)
{
bool hopLe = KiemTraPassword(line);
[Link](line + " : " + (hopLe ? "Yes" : "No"));
}
}

[Link]("Da kiem tra xong Password!");


}
}

You might also like