HOME FORUMS MEMBERS RECENT POSTS LOG IN  
× Авторизация
Имя пользователя:
Пароль:
Нет аккаунта? Регистрация
Баннер 1   Баннер 2
НОВЫЕ ТОРГОВАЯ НОВОСТИ ЧАТ
loading...
Скрыть
Вернуться   ANTICHAT > ПРОГРАММИРОВАНИЕ > Общие вопросы программирования
   
Ответ
 
Опции темы Поиск в этой теме Опции просмотра

  #1  
Старый 03.11.2021, 19:51
TimeLordRu
Участник форума
Регистрация: 09.06.2018
Сообщений: 150
С нами: 4173454

Репутация: 83
По умолчанию

C#:





Код:
using
System
;
using
System
.
IO
;
class
Test
{
public
static
void
Main
(
)
{
int
[
]
x
=
new
int
[
50
]
;
int
i
=
0
;
try
{
using
(
StreamReader
sr
=
new
StreamReader
(
"chisla.txt"
)
)
using
(
StreamWriter
sw
=
new
StreamWriter
(
"Pesnya.lua"
)
)
{
string
line
;
sw
.
WriteLine
(
"function main()"
)
;
sw
.
WriteLine
(
"if not isSampfuncsLoaded() or not isSampLoaded() then return end"
)
;
sw
.
WriteLine
(
"while not isSampAvailable() do wait(100) end"
)
;
sw
.
WriteLine
(
"while true do wait(0)"
)
;
sw
.
WriteLine
(
"if testCheat('RES') then"
)
;
sw
.
WriteLine
(
"thisScript():reload()"
)
;
sw
.
WriteLine
(
"end"
)
;
sw
.
WriteLine
(
"if testCheat('SONG') then"
)
;
//sw.WriteLine("wait(1000)");
while
(
(
line
=
sr
.
ReadLine
(
)
)
!=
null
)
{
int
.
TryParse
(
line
,
out
x
[
i
]
)
;
Console
.
WriteLine
(
$
"{line}, {i + 1}-й элемент равен {x[i]}"
)
;
DirectoryInfo
[
]
cDirs
=
new
DirectoryInfo
(
@"c:\").GetDirectories();

sw.WriteLine($"
sampSendChat
(
'{line}'
)
"
)
;
sw
.
WriteLine
(
"wait(1000)"
)
;
x
[
i
]
++
;
i
++
;
}
sw
.
WriteLine
(
"end"
)
;
sw
.
WriteLine
(
"end"
)
;
sw
.
WriteLine
(
"end"
)
;
}
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
"The file could not be read:"
)
;
Console
.
WriteLine
(
e
.
Message
)
;
}
}
}


Этот код ищет, считывает и создает новый файл по адресу C:\Users\User\source\repos\ConsoleApp1\ConsoleApp1 \bin\Debug\netcoreapp3.1 . Можно ли как-то сделать, чтобы он в другом месте обрабатывал текстовый файл?
 
Ответить с цитированием

  #2  
Старый 09.11.2021, 18:32
kivija3070
Новичок
Регистрация: 26.10.2021
Сообщений: 14
С нами: 2395546

Репутация: 8
По умолчанию

Цитата:
Сообщение от TimeLordRu  

C#:





Код:
using
System
;
using
System
.
IO
;
class
Test
{
public
static
void
Main
(
)
{
int
[
]
x
=
new
int
[
50
]
;
int
i
=
0
;
try
{
using
(
StreamReader
sr
=
new
StreamReader
(
"chisla.txt"
)
)
using
(
StreamWriter
sw
=
new
StreamWriter
(
"Pesnya.lua"
)
)
{
string
line
;
sw
.
WriteLine
(
"function main()"
)
;
sw
.
WriteLine
(
"if not isSampfuncsLoaded() or not isSampLoaded() then return end"
)
;
sw
.
WriteLine
(
"while not isSampAvailable() do wait(100) end"
)
;
sw
.
WriteLine
(
"while true do wait(0)"
)
;
sw
.
WriteLine
(
"if testCheat('RES') then"
)
;
sw
.
WriteLine
(
"thisScript():reload()"
)
;
sw
.
WriteLine
(
"end"
)
;
sw
.
WriteLine
(
"if testCheat('SONG') then"
)
;
//sw.WriteLine("wait(1000)");
while
(
(
line
=
sr
.
ReadLine
(
)
)
!=
null
)
{
int
.
TryParse
(
line
,
out
x
[
i
]
)
;
Console
.
WriteLine
(
$
"{line}, {i + 1}-й элемент равен {x[i]}"
)
;
DirectoryInfo
[
]
cDirs
=
new
DirectoryInfo
(
@"c:\").GetDirectories();

sw.WriteLine($"
sampSendChat
(
'{line}'
)
"
)
;
sw
.
WriteLine
(
"wait(1000)"
)
;
x
[
i
]
++
;
i
++
;
}
sw
.
WriteLine
(
"end"
)
;
sw
.
WriteLine
(
"end"
)
;
sw
.
WriteLine
(
"end"
)
;
}
}
catch
(
Exception
e
)
{
Console
.
WriteLine
(
"The file could not be read:"
)
;
Console
.
WriteLine
(
e
.
Message
)
;
}
}
}


Этот код ищет, считывает и создает новый файл по адресу C:\Users\User\source\repos\ConsoleApp1\ConsoleApp1 \bin\Debug\netcoreapp3.1 . Можно ли как-то сделать, чтобы он в другом месте обрабатывал текстовый файл?
using (StreamReader sr = new StreamReader("chisla.txt"))

using (StreamWriter sw = new StreamWriter("Pesnya.lua"))

Просто указать полный путь до файла, а так он и будет в рабочей папке создавать...
 
Ответить с цитированием
Ответ



Предыдущая тема Следующая тема

Здесь присутствуют: 1 (пользователей: 0 , гостей: 1)
 


Быстрый переход




ANTICHAT ™ © 2001- Antichat Kft.