Вывести на экран все символы, расположенные внутри скобок - C#
Формулировка задачи:
Дана строка символов, среди которых есть одна открывающаяся и одна закрывающаяся скобка. Вывести на экран все символы, расположенные внутри этих скобок.
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int i, l, r, z;
string s, b;
Console.WriteLine("Введите строку :");
s = Console.ReadLine();
for (i = 1; i < s.Length; i++) ;
{
if (s[i] == '(')
l = i;
if (s[i] == ')') ;
r = i;
}
}
}
}Решение задачи: «Вывести на экран все символы, расположенные внутри скобок»
textual
Листинг программы
using System;
class demo
{
static void Main()
{
Console.WriteLine("введите строку : ");
string str = Console.ReadLine();
int begin = str.IndexOf('(');
int end = str.LastIndexOf(')');
if (begin != -1 && end != -1)
for (begin +=1; begin < end; begin++) Console.Write(str[begin]);
else Console.WriteLine("неверный формат");
Console.WriteLine();
Console.ReadKey(true);
}
}