ВУЗ:
Составители:
Рубрика:
59
размер массива (data.Length) минус 1. Поэтому материализация этого
псевдокода в кодах будет выглядеть следующим образом:
public class FileWorker {
public void processFile(string inFileName, string
outFileName) {
try {
string[] content = File.ReadAllLines(inFileName);
if (content.Length == 0) {
throw new ApplicationException("в файле нет строк");
}
string lastStr = content[content.Length - 1];
string[] resLines = new string[content.Length];
for (int i = 0; i < content.Length;i++ ) {
StringWorker worker = new StringWorker();
worker.str = content[i];
worker.processString(lastStr);
resLines[i] = worker.str;
}
File.WriteAllLines(outFileName, resLines);
} catch {
Console.WriteLine("ошибка");
}
}
}
7. И приведем полный код задачи
using System;
using System.IO;
using System.Linq;
namespace ConsoleApplication17 {
class Program {
static void Main() {
Console.WriteLine("введите имя входного файла: ");
string inFileName = Console.ReadLine();
Console.WriteLine("введите имя выходного файла: ");
string outFileName = Console.ReadLine();
FileWorker fileWorker = new FileWorker();
fileWorker.processFile(inFileName, outFileName);
}
}
public class StringWorker {
public string str;
public bool needDelWord(string word, string lastStr) {
for (int i = 0; i < word.Length;i++ ) {
if (lastStr.Contains(word[i])) {
return true;
}
}
return false;
}
private bool isSeparator(char c) {
Страницы
- « первая
- ‹ предыдущая
- …
- 57
- 58
- 59
- 60
- 61
- …
- следующая ›
- последняя »