bl4ck
bl4ck
CC#
Created by bl4ck on 3/17/2024 in #help
Path.Combine says "Illegal character in path"
This is the path. Why is it illegal? C:\Users\itsbl\AppData\LocalLow\bl4ckdev x XDev\Airborne\Levels\Untitled (143).level
9 replies
CC#
Created by bl4ck on 3/9/2024 in #help
Can't use | operator in case?
No description
8 replies
CC#
Created by bl4ck on 1/17/2024 in #help
Fastest way to read specific line from string
I'm working on a project that involves reading specific lines of a file multiple times. I'm afraid this ReadLine function is the reason it takes a painfully long time to finish so I'm trying to optimize it, but I'm not sure what is the fastest way to do it This was my old code:
//public static string ReadLine(string text, int lineNumber)
//{
// var reader = new StringReader(text);
//
// string line;
// int currentLineNumber = 0;
//
// do
// {
// currentLineNumber += 1;
// line = reader.ReadLine();
// }
// while (line != null && currentLineNumber < lineNumber);
//
// return (currentLineNumber == lineNumber) ? line :
// string.Empty;
//}
//public static string ReadLine(string text, int lineNumber)
//{
// var reader = new StringReader(text);
//
// string line;
// int currentLineNumber = 0;
//
// do
// {
// currentLineNumber += 1;
// line = reader.ReadLine();
// }
// while (line != null && currentLineNumber < lineNumber);
//
// return (currentLineNumber == lineNumber) ? line :
// string.Empty;
//}
This is my new code: (prevText is in place in case it reads the same thing so that it skips splitting it)
private string[] splitString = null;
public static string prevText = "";
public static string ReadLine(string text, int lineNumber)
{

if (!text.Equals(prevText)) Instance.splitString = text.Split('\n');

prevText = text;
return Instance.splitString[lineNumber - 1];
}
private string[] splitString = null;
public static string prevText = "";
public static string ReadLine(string text, int lineNumber)
{

if (!text.Equals(prevText)) Instance.splitString = text.Split('\n');

prevText = text;
return Instance.splitString[lineNumber - 1];
}
14 replies