Copy and Paste a range of lines from text file into text area then delete lines from file?

JIMBOB

Пользователь
Регистрация
07.04.2022
Сообщения
35
Благодарностей
0
Баллы
6
Hello,

I'm having trouble working out how to copy a range of data (500 lines) from a text file to the clipboard and once the data has been copied to the clipboard, the lines are removed from the text file.

Even knowing how to copy a range of lines from a text file (or table) to the clipboard would probably send me in the right direction.

Any help would be appreciated.

Thank you.
 

robertign0

Пользователь
Регистрация
20.01.2022
Сообщения
33
Благодарностей
6
Баллы
8
have you found a solution for this ? having similar problem
 

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 761
Благодарностей
2 401
Баллы
113
have you found a solution for this ? having similar problem
C#:
int count = 500;
string path = @"C:\Users\User\Desktop\filelines.txt";
var lines = File.ReadLines(path);

string[] data = null;
if(lines.Count() > count) {
    data = lines.Take(count).ToArray();
    lines = lines.Skip(count);
}
else {
    data = lines.ToArray();
    lines = Enumerable.Empty<string>();
}

File.WriteAllLines(path, lines.ToArray());

string text = data.Length > 0 ? string.Join(Environment.NewLine, data) : string.Empty;

lock(SyncObjects.InputSyncer) {
    if(!string.IsNullOrEmpty(text))    System.Windows.Forms.Clipboard.SetText(text);
}
 
  • Спасибо
Реакции: robertign0

robertign0

Пользователь
Регистрация
20.01.2022
Сообщения
33
Благодарностей
6
Баллы
8
Thank you, Спасибо , Благодарам (Македонски) :-)
will try to work with this
 
  • Спасибо
Реакции: BAZAg

BAZAg

Client
Регистрация
08.11.2015
Сообщения
1 761
Благодарностей
2 401
Баллы
113
  • Спасибо
Реакции: robertign0

Кто просматривает тему: (Всего: 1, Пользователи: 0, Гости: 1)