本文整理汇总了C#中TextReader.ReadLine方法的典型用法代码示例。如果您正苦于以下问题:C# TextReader.ReadLine方法的具体用法?C# TextReader.ReadLine怎么用?C# TextReader.ReadLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextReader
的用法示例。
在下文中一共展示了TextReader.ReadLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: LoadStructure
public static object LoadStructure(TextReader reader, object obj, string until, Hashtable listprev)
{
object result = obj;
until = until.Trim();
string line = reader.ReadLine();
if (line != null) line = line.Trim();
while ((line != null) && (line != until))
{
if (line == null) break;
if (line == "") goto cont;
if (line[0] == '#') goto cont;
string[] elt;
if (!ReadEltFromLine_IFP(line, out elt)) goto cont;
if (elt[0] == "copy")
{
CopyObject(listprev[elt[1]], result);
goto cont;
}
FieldInfo finfo = result.GetType().GetField(elt[0]);
// if (finfo!=null) {
if (finfo.FieldType == typeof(float)) finfo.SetValue(result, float.Parse(elt[1]));
if (finfo.FieldType == typeof(string)) finfo.SetValue(result, elt[1]);
if (finfo.FieldType == typeof(bool)) finfo.SetValue(result, bool.Parse(elt[1]));
// }
cont:
line = reader.ReadLine();
if (line != null) line = line.Trim();
}
return result;
}
示例2: Run
private void Run(TextReader rd)
{
int T = int.Parse(rd.ReadLine());
for (; T > 0; T--) {
int N = int.Parse(rd.ReadLine());
string[] ln = rd.ReadLine().Split(' ');
char[] chars = new char[N];
for (int i = 0; i < N; i++) {
chars[i] = (char)(int.Parse(ln[i]) + 'a');
}
Console.WriteLine(Solve(new string(chars), Player.Alice, Player.Bob));
}
//Console.ReadKey();
}
示例3: Start
// Use this for initialization
void Start()
{
credits = new List<string>();
positionRect = new List<Rect>();
// Create reader & open file
try{
tr = new StreamReader(path);
string temp;
int count = 0;
while((temp = tr.ReadLine()) != null)
{
credits.Add(temp);
positionRect.Add(new Rect(Screen.width/4 - Screen.width/8, (float)(Screen.height * 0.07 * count + Screen.height), (float)(Screen.width/2 + Screen.width/4), (float)(Screen.height * 0.5)));
count++;
}
// Close the stream
tr.Close();
}
catch(FileLoadException e) {
Debug.LogException(e);
credits.Add("Error while loading credits file.");
}
}
示例4: Run
void Run(TextReader rd)
{
string[] ln = rd.ReadLine().Split(' ');
N = int.Parse(ln[0]);
K = int.Parse(ln[1]);
boards = new int[N + 1];
for(int i = 1; i <= N; i++) {
boards[i] = int.Parse(rd.ReadLine());
}
mem = new Dictionary<int, IDictionary<int, long>>((int)(N * 1.5));
long max = Dfs(1, 0);
Console.WriteLine(max);
}
示例5: Parse
public string[][] Parse(TextReader reader)
{
var context = new ParserContext();
ParserState currentState = ParserState.LineStartState;
string next;
while ((next = reader.ReadLine()) != null)
{
foreach (char ch in next)
{
switch (ch)
{
case CommaCharacter:
currentState = currentState.Comma(context);
break;
case QuoteCharacter:
currentState = currentState.Quote(context);
break;
default:
currentState = currentState.AnyChar(ch, context);
break;
}
}
currentState = currentState.EndOfLine(context);
}
List<string[]> allLines = context.GetAllLines();
return allLines.ToArray();
}
示例6: Parse
public string[][] Parse(TextReader reader)
{
var context = new ParserContext();
if (MaxColumnsToRead != 0)
context.MaxColumnsToRead = MaxColumnsToRead;
ParserState currentState = ParserState.LineStartState;
string next;
while ((next = reader.ReadLine()) != null)
{
foreach (char ch in next)
{
switch (ch)
{
case CommaCharacter:
currentState = currentState.Comma(context);
break;
case QuoteCharacter:
currentState = currentState.Quote(context);
break;
default:
currentState = currentState.AnyChar(ch, context);
break;
}
}
currentState = currentState.EndOfLine(context);
}
List<string[]> allLines = context.GetAllLines();
if (TrimTrailingEmptyLines && allLines.Count > 0)
{
bool isEmpty = true;
for (int i = allLines.Count - 1; i >= 0; i--)
{
// ReSharper disable RedundantAssignment
isEmpty = true;
// ReSharper restore RedundantAssignment
for (int j = 0; j < allLines[i].Length; j++)
{
if (!String.IsNullOrEmpty(allLines[i][j]))
{
isEmpty = false;
break;
}
}
if (!isEmpty)
{
if (i < allLines.Count - 1)
allLines.RemoveRange(i + 1, allLines.Count - i - 1);
break;
}
}
if (isEmpty)
allLines.RemoveRange(0, allLines.Count);
}
return allLines.ToArray();
}
示例7: Answer
public void Answer(TextReader input)
{
string line = input.ReadLine();
int nOfCases = Convert.ToInt32(line);
for (int caseNo = 1; caseNo <= nOfCases; caseNo++)
{
//Size
line = input.ReadLine();
int rows = Convert.ToInt32(line.Split(' ')[0]);
int cols = Convert.ToInt32(line.Split(' ')[1]);
//Init pattern
int[][] pattern = new int[rows][];
for (int i = 0; i < rows; i++)
{
pattern[i] = new int[cols];
}
//Read pattern
for (int row = 0; row < rows; row++)
{
line = input.ReadLine();
var values = line.Split(' ');
for(int col = 0; col < cols; col++)
pattern[row][col] = Convert.ToInt32(values[col]);
}
string result = "YES";
for (int row = 0; row < rows; row++)
{
for (int col = 0; col < cols; col++)
{
if (RowHasGreaterThan(pattern[row][col],row,pattern)
&& ColHasGreaterThan(pattern[row][col], col, pattern))
result = "NO";
}
}
Console.Out.WriteLine("Case #{0}: {1}", caseNo, result);
}
}
示例8: Start
// Use this for initialization
void Start()
{
textFile = (TextAsset)Resources.Load("embedded", typeof(TextAsset));
reader = new StringReader(textFile.text);
string lineOfText;
int lineNumber = 0;
while ((lineOfText = reader.ReadLine()) != null)
{
if (lineNumber % 2 == 0)
{
sentences.Add(lineOfText);
}
else
{
clues.Add(lineOfText);
}
lineNumber++;
}
SendMessage("Gather");
}
示例9: Load
/// <summary>
/// Load properties with specified text reader.
/// </summary>
/// <param name="reader">Text reader.</param>
public void Load(TextReader reader)
{
Clear();
string line = "";
string currentComment = "";
while ((line = reader.ReadLine()) != null)
{
line = line.Trim();
if (line.StartsWith("["))
{
if (line.EndsWith("]"))
{
mCurrentGroup = line.Substring(1, line.Length - 2);
if (mCurrentGroup != "")
{
mCurrentGroup += "/";
}
}
else
{
Debug.LogError("Trailing ']' character not found in line: " + line);
}
}
else
if (
line.StartsWith(";")
||
line.StartsWith("#")
)
{
currentComment = line.Substring(1).Trim();
}
else
{
int index = line.IndexOf("=");
if (index > 0)
{
string key = line.Substring(0, index).Trim();
string value = line.Substring(index + 1).Trim();
if (value.Length >= 2 && value[0] == '\"' && value[value.Length - 1] == '\"')
{
value = value.Substring(1, value.Length - 2);
}
Set(key, value, currentComment);
currentComment = "";
}
}
}
mCurrentGroup = "";
}
示例10: LeesVolgendeRegel
public static string LeesVolgendeRegel(ref int regelTeller, TextReader streamReader)
{
regelTeller++;
return streamReader.ReadLine();
}
示例11: FromReader
public static IEnumerable<IList<string>> FromReader(TextReader csv, bool ignoreFirstLine)
{
if (ignoreFirstLine) csv.ReadLine();
IList<string> result = new List<string>();
StringBuilder curValue = new StringBuilder();
char c;
c = (char)csv.Read();
while (csv.Peek() != -1)
{
switch (c)
{
case ',': //empty field
result.Add("");
c = (char)csv.Read();
break;
case '"': //qualified text
case '\'':
char q = c;
c = (char)csv.Read();
bool inQuotes = true;
while (inQuotes && csv.Peek() != -1)
{
if (c == q)
{
c = (char)csv.Read();
if (c != q)
inQuotes = false;
}
if (inQuotes)
{
curValue.Append(c);
c = (char)csv.Read();
}
}
result.Add(curValue.ToString());
curValue = new StringBuilder();
if (c == ',') c = (char)csv.Read(); // either ',', newline, or endofstream
break;
case '\n': //end of the record
case '\r':
//potential bug here depending on what your line breaks look like
if (result.Count > 0) // don't return empty records
{
yield return result;
result = new List<string>();
}
c = (char)csv.Read();
break;
default: //normal unqualified text
while (c != ',' && c != '\r' && c != '\n' && csv.Peek() != -1)
{
curValue.Append(c);
c = (char)csv.Read();
}
result.Add(curValue.ToString());
curValue = new StringBuilder();
if (c == ',') c = (char)csv.Read(); //either ',', newline, or endofstream
break;
}
}
if (curValue.Length > 0) //potential bug: I don't want to skip on a empty column in the last record if a caller really expects it to be there
result.Add(curValue.ToString());
if (result.Count > 0)
yield return result;
}
示例12: ProcessFile
private static int ProcessFile(string filename, TextReader reader, TextWriter writer)
{
int lineNum = 1;
string line = reader.ReadLine();
int matches = 0;
bool filePrinted = false;
string newLine = null;
while (line != null)
{
newLine = line;
Match match = regex.Match(line);
if (match.Success)
{
matches++;
totalMatches++;
if (replacePattern != null)
newLine = regex.Replace(line, replacePattern);
if (filenamesOnly)
{
if (!quiet && !filePrinted) Console.WriteLine(filename);
filePrinted = true;
if (replacePattern == null)
break;
}
else if (!quiet)
{
if (!linesOnly) Console.Write(filename + "(" + lineNum + "): ");
if (showExpr)
{
int i = 0;
while (match != null && match.Success)
{
if (replacePattern == null || showBothExprs)
Console.Write(match.ToString());
if (showBothExprs)
Console.Write(" -> ");
if (replacePattern != null)
Console.Write(match.Result(replacePattern));
Console.WriteLine();
match = match.NextMatch();
i++;
}
}
else
{
Console.Write(line);
if (replacePattern != null)
Console.Write(" -> " + newLine);
Console.WriteLine();
}
}
}
if (replacePattern != null && !testReplace)
writer.WriteLine(newLine);
line = reader.ReadLine();
lineNum++;
}
return matches;
}
示例13: Run
/// <summary>
/// Runs the specified executable with the provided arguments and returns the process' exit code.
/// </summary>
/// <param name="output">Recieves the output of either std/err or std/out</param>
/// <param name="input">Provides the line-by-line input that will be written to std/in, null for empty</param>
/// <param name="exe">The executable to run, may be unqualified or contain environment variables</param>
/// <param name="args">The list of unescaped arguments to provide to the executable</param>
/// <returns>Returns process' exit code after the program exits</returns>
/// <exception cref="System.IO.FileNotFoundException">Raised when the exe was not found</exception>
/// <exception cref="System.ArgumentNullException">Raised when one of the arguments is null</exception>
/// <exception cref="System.ArgumentOutOfRangeException">Raised if an argument contains '\0', '\r', or '\n'
public static int Run(Action<string> output, TextReader input, string exe, params string[] args)
{
if (String.IsNullOrEmpty(exe))
throw new FileNotFoundException();
if (output == null)
throw new ArgumentNullException("output");
ProcessStartInfo psi = new ProcessStartInfo();
psi.UseShellExecute = false;
psi.RedirectStandardError = true;
psi.RedirectStandardOutput = true;
psi.RedirectStandardInput = true;
psi.WindowStyle = ProcessWindowStyle.Hidden;
psi.CreateNoWindow = true;
psi.ErrorDialog = false;
psi.WorkingDirectory = WorkingFolder;
psi.FileName = FindExePath(exe);
psi.Arguments = EscapeArguments(args);
using (Process process = Process.Start(psi))
using (ManualResetEvent mreOut = new ManualResetEvent(false),
mreErr = new ManualResetEvent(false))
{
process.OutputDataReceived += (o, e) => { if (e.Data == null) mreOut.Set(); else output(e.Data); };
process.BeginOutputReadLine();
process.ErrorDataReceived += (o, e) => { if (e.Data == null) mreErr.Set(); else output(e.Data); };
process.BeginErrorReadLine();
string line;
while (input != null && null != (line = input.ReadLine()))
process.StandardInput.WriteLine(line);
process.StandardInput.Close();
process.WaitForExit();
mreOut.WaitOne();
mreErr.WaitOne();
return process.ExitCode;
}
}
示例14: fscanf
static public int fscanf(TextReader stream, String format, Object[] results)
{
String s = stream.ReadLine();
if (null == s)
return 0;
return sscanf(s, format, results);
}
示例15: LoadDatabasesFromStream
private static List<QuestionDatabase> LoadDatabasesFromStream(TextReader reader, bool isLocal)
{
List<QuestionDatabase> databases = new List<QuestionDatabase>();
if(isLocal) globalFileIndex = int.Parse(reader.ReadLine());
int databasesCount = int.Parse(reader.ReadLine());
for(int n = 0; n < databasesCount; n++){
QuestionDatabase database = new QuestionDatabase();
database.name = reader.ReadLine();
database.url = reader.ReadLine();
if(isLocal){
database.fileIndex = int.Parse(reader.ReadLine());
database.used = bool.Parse(reader.ReadLine());
database.downloaded = bool.Parse(reader.ReadLine());
}
databases.Add(database);
}
return databases;
}