Answer the question
In order to leave comments, you need to log in
How to find a line after a character?
Hello!
The question is this: there is a found line print(' after it, you need to find a word that will begin with ' (which we found together with print( ), and wrap its contents in one more line. How can this be done?
static void Main(string[] args)
{
string code;
code = Console.ReadLine();
if (FindCode(code, "print('"))
{
}
bool FindCode(string code, string codeToFind)
{
Do:
if (code.Length < codeToFind.Length)
return false;
else
{
for (int i = 0; i < code.Length; i++)
{
for (int j = 0; j < codeToFind.Length; j++)
{
if (code[i] == codeToFind[j])
return true;
else
return false;
goto Do;
}
}
}
return false;
}
void Print(string text)
{
Console.WriteLine(text);
}
void PrintFor(string text, int repeat)
{
for (int i = 0; i < repeat; i++)
{
Console.WriteLine(text);
}
}
Console.ReadKey();
Answer the question
In order to leave comments, you need to log in
using System;
using System.Text.RegularExpressions;
namespace ConsoleApp2
{
class Program
{
static void Main(string[] args)
{
string input = "blablabla print('Test 1'); blabla print('Test 2')";
string pattern = @"print\(\'([^\']*)\'\)";
foreach (Match m in Regex.Matches(input, pattern))
{
Console.WriteLine(m.Groups[1].Value);
} // foreach
Console.ReadLine();
} // Main
} // class Program
} // namespace
Test 1
Test 2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question