Index was out of range - не понемаю как такое возмозно - C#
Формулировка задачи:
Листинг программы
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.IO;
- namespace lab2_2
- {
- class Program
- {
- static void Main(string[] args)
- {
- try
- {
- string f1;
- string f2;
- Console.WriteLine("enter file location for modification:");
- f1 = Console.ReadLine();
- string[] str = File.ReadAllLines(f1);
- Console.WriteLine("enter name and path output file");
- f2 = Console.ReadLine();
- int b;
- int len = str.Length;
- Console.WriteLine(len);
- using (StreamWriter sw = File.CreateText(f2))
- {
- sw.AutoFlush = true;
- for (int i = 2; i <len-1; i++)
- {
- b = str[i].IndexOf(";");
- str[i].Insert(b,"\n"); // здеся не канает
- sw.WriteLine(str[i]);
- }
- }
- Console.WriteLine("all coments erase!");
- Console.ReadLine();
- }
- catch (FileNotFoundException e)
- {
- Console.WriteLine("File not found! " + e.Message);
- Console.ReadKey();
- }
- }
- }
- }
Решение задачи: «Index was out of range - не понемаю как такое возмозно»
textual
Листинг программы
- if (str[i].Contains(";")) {
- str[i].Insert(str[i].IndexOf(";"), "\n");
- Console.Write(str[i] + "\n");
- }
ИИ поможет Вам:
- решить любую задачу по программированию
- объяснить код
- расставить комментарии в коде
- и т.д