Переведите пожалуйста с С на C#: заменить “ing” на окончание “ed”
Формулировка задачи:
переведите пожалуйста с С на си шарп
Дана строка символов. В тех словах которые оканчиваются сочетанием букв “ing”,заменить это окончание на “ed”.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#define is_delim(c) (!(c) || isspace((c)) || ispunct((c)))
char* s_rep(char* s, const char* o, const char* n){
size_t i, j;
char* p, *t = s;
i = strlen(o);
j = strlen(n);
if(i < j) //новое окончание должно быть не больше
return t;
while((s = strstr(s, o)) != NULL){
if(is_delim(*(s + i)))
break;
s += i;
}
if(s == NULL)
return t;
for(p = s; *s; *s = *p){
if(! strncmp(p, o, i) && is_delim(*(p + i))){
strncpy(s, n, j);
s += j;
p += j + (i - j);
continue;
} else
++s;
++p;
}
return t;
}
int main(void){
char s[] = "ping, king, ings stinger (sting), inging";
puts(s);
puts( s_rep(s, "ing", "ed") );
return 0;
}Решение задачи: «Переведите пожалуйста с С на C#: заменить “ing” на окончание “ed”»
textual
Листинг программы
using System;
using System.Text.RegularExpressions;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
string input = "ping, king, ings stinger(sting), inging";
Regex regex = new Regex(@"(ing)\b");
Console.WriteLine(regex.Replace(input, "ed"));
Console.ReadKey();
}
}
}