ich mit diesem Code Abfrage LINQWie kann ich Ausgabe in einer bestimmten Art und Weise drucken
static public void BracesRule(String input)
{
//Regex for Braces
string BracesRegex = @"\{|\}";
Dictionary<string, string> dictionaryofBraces = new Dictionary<string, string>()
{
//{"String", StringRegex},
//{"Integer", IntegerRegex },
//{"Comment", CommentRegex},
//{"Keyword", KeywordRegex},
//{"Datatype", DataTypeRegex },
//{"Not included in language", WordRegex },
//{"Identifier", IdentifierRegex },
//{"Parenthesis", ParenthesisRegex },
{"Brace", BracesRegex },
//{"Square Bracket", ArrayBracketRegex },
//{"Puncuation Mark", PuncuationRegex },
//{"Relational Expression", RelationalExpressionRegex },
//{"Arithmetic Operator", ArthimeticOperatorRegex },
//{"Whitespace", WhitespaceRegex }
};
var matches = dictionaryofBraces.SelectMany(a => Regex.Matches(input, a.Value)
.Cast<Match>()
.Select(b =>
new
{
Index = b.Index,
Value = b.Value,
Token = a.Key
}))
.OrderBy(a => a.Index).ToList();
for (int i = 0; i < matches.Count; i++)
{
if (i + 1 < matches.Count)
{
int firstEndPos = (matches[i].Index + matches[i].Value.Length);
if (firstEndPos > matches[(i + 1)].Index)
{
matches.RemoveAt(i + 1);
i--;
}
}
}
foreach (var match in matches)
{
Console.WriteLine(match);
}
}
es Ausgabe geschrieben haben, ist so etwas wie dieses {Index = 0, Wert = {, Token = Brace}
Aber ich will Output sein wie {BRACE
Könnten Sie ein littble bisschen mehr auf Ihr Problem näher erläutern? Können Sie ein Beispiel für Ihre Eingabe angeben? Welchen Teil möchten Sie genau ändern (und wie)? Die Ausgabe? – pasty
Dies ist ein Tokenizer. Lexer Eingang: {} Ausgang: {Index = 0, Wert = {, Token = Brace} {Index = 1, Wert =}, Token = Brace} Aber ich will Output sein wie Ausgang: {Brace } Brace – Ali
Das ist Ihr Code, aber Sie können die Ausgabeformatierung nicht ändern? – pasty