Home c# method that translates from a brick language

method that translates from a brick language

Author

Date

Category

Good day, gentlemen!

just started learning programming on C #. There is a task: Create a method that translates to a brick language and back. With the translation to the brick, I figured out, and how to back? Help

using system;
Public Static Class Trans
{
  Private Static Char [] _vovels = new char [] {'a', 'o', 'e', ​​'and', 'y', 'me', 'y', 'u'};
  Private Static Bool Isvovel (Char C)
  {
    for (var i = 0; i & lt; _vovels.length; i ++)
    {
      if (_vovels [i] == c)
        RETURN TRUE;
    }
    RETURN FALSE;
  }
  Public Static String Tubick (String Str)
  {
    var result = "";
    for (var i = 0; i & lt; str.length; i ++)
    {
      Result = Result + Str [i];
      IF (ISVOVEL (STR [I]) == TRUE)
        result = result + 'with' + str [i];
    }
    RETURN RESULT;
  }
  Public Static String Frombrick (String Str)
  {
    // Here you need to make a translation from the brick.
  }
}
Public Class App
{
  Public Void Main ()
  {
    Console.Writeline (TRANS.TOBRICK ("Hi, Dubin"));
    // Translation on the brick will be like this: "Prefers, DuSubisinas"
  }
}

Answer 1, Authority 100%

As an option, you can use Regular expressions :

var text = "hello, duby";
var bricktext = regex.replace (text, "([Ayoyyuyuue])", "$ 1c $ 1");
var NormalText = Regex.Replace (BrickText, "([Aoeiyuyueu]) C \\ 1", "$ 1");

Example You can see here .

Update

as an option, without regular expressions, can be done like this:

private static Readonly list & lt; string & gt; Vovels = New List & LT; String & GT; {"A", "O", "E", "and", "Yu", "I", "U", "E"};
Public Static Void Main ()
{
  var text = "Hi, duby";
  Var BrickText = Text;
  VOVELS.FOREACH (V = & GT; BrickText = BrickText.Replace (V, GetBrickTextForchar (V)));
  var normaltext = brickText;
  VOVELS.FOREACH (V = & GT; NormalText = NormalText.REPLACE (GetBrickTextForchar (V), V));
}
Static String GetbrickTextForchar (String Textchar)
{
  RETURN TEXTCHAR + "C" + TEXTCHAR;
}

Example You can see here .

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions