Created
August 6, 2015 18:09
-
-
Save money4honey/5192409e767d8cd05b12 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.IO; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace myClasses | |
{ | |
public class ListMaster | |
{ | |
public static string getLineFromFile(string filePath, int index) | |
{ | |
string[] lines = File.ReadAllLines(filePath); | |
return lines[index]; | |
} | |
public static void deleteLineFromFile(string filePath, int lineNumber) | |
{ | |
List<string> list = File.ReadAllLines(filePath).ToList(); | |
list.RemoveAt(lineNumber); | |
File.WriteAllLines(filePath, list.ToArray()); | |
} | |
public static void deleteDoubles(string filePath) | |
{ | |
string[] lines = File.ReadAllLines(filePath); | |
File.WriteAllLines(filePath, lines.Distinct().ToArray()); | |
} | |
public static void deleteEmptyLines(string filePath) | |
{ | |
string line; | |
List<string> list = File.ReadAllLines(filePath).ToList(); | |
for (int i = 0; i < list.Count; i++) | |
{ | |
line = list[i]; | |
if (line == "") list.RemoveAt(i); | |
} | |
File.WriteAllLines(filePath, list.ToArray()); | |
} | |
public static string[] deleteEmptyLines(string[] array) | |
{ | |
List<string> list = array.ToList(); | |
int index = 0; | |
foreach (string line in list) { | |
if (line == "") list.RemoveAt(index); | |
index++; | |
} | |
return list.ToArray(); | |
} | |
public static int getListCount(string path) { | |
string[] array = File.ReadAllLines(path); | |
string[] arrayClean = deleteEmptyLines(array); | |
return arrayClean.Length; | |
} | |
public static void clearFile(string path) { | |
File.WriteAllText(path, String.Empty); | |
} | |
public static string miltiReplace(string text, string[] replaceArray) { | |
if (replaceArray.Contains(";")){ | |
foreach (string item in replaceArray) { | |
string[] mas = item.Split(';'); | |
text = text.Replace(mas[0], mas[1]); | |
} | |
return text; | |
} | |
else return null; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment