Пример #1
0
 /// <summary>
 /// Converts or manipulates the <see cref="string" /> value based on the specified <see cref="StringConverterMethod" /> parameter.
 /// </summary>
 /// <param name="value">The <see cref="string" /> value to convert.</param>
 /// <param name="parameter">A parameter <see cref="object" /> that specifies the parameter used in some of the <see cref="StringConverterMethod" /> methods.</param>
 /// <returns>
 /// An <see cref="object" /> with the result of the conversion.
 /// </returns>
 public override object Convert(string value, object parameter)
 {
     return(Method switch
     {
         StringConverterMethod.Concat => value + parameter,
         StringConverterMethod.Trim => value?.Trim(),
         StringConverterMethod.TrimStart => value?.TrimStart(),
         StringConverterMethod.TrimStartString => value?.TrimStartString(parameter?.ToString()),
         StringConverterMethod.TrimStartStringIgnoreCase => value?.TrimStartString(parameter?.ToString(), true),
         StringConverterMethod.TrimEnd => value?.TrimEnd(),
         StringConverterMethod.TrimEndString => value?.TrimEndString(parameter?.ToString()),
         StringConverterMethod.TrimEndStringIgnoreCase => value?.TrimEndString(parameter?.ToString(), true),
         StringConverterMethod.ToLower => value?.ToLower(),
         StringConverterMethod.ToUpper => value?.ToUpper(),
         StringConverterMethod.ToCamelCase => value?.ChangeCasing(StringCasing.CamelCase),
         StringConverterMethod.ToLowerSnakeCase => value?.ChangeCasing(StringCasing.LowerSnakeCase),
         StringConverterMethod.ToUpperSnakeCase => value?.ChangeCasing(StringCasing.UpperSnakeCase),
         StringConverterMethod.ToLowerKebabCase => value?.ChangeCasing(StringCasing.LowerKebabCase),
         StringConverterMethod.ToUpperKebabCase => value?.ChangeCasing(StringCasing.UpperKebabCase),
         StringConverterMethod.Substring => value?.Substring((int)parameter),
         StringConverterMethod.Left => value?.Left((int)parameter),
         StringConverterMethod.Right => value?.Right((int)parameter),
         StringConverterMethod.StartsWith => value?.StartsWith(parameter?.ToString()) == true,
         StringConverterMethod.StartsWithIgnoreCase => value?.StartsWith(parameter?.ToString(), StringComparison.OrdinalIgnoreCase) == true,
         StringConverterMethod.EndsWith => value?.EndsWith(parameter?.ToString()) == true,
         StringConverterMethod.EndsWithIgnoreCase => value?.EndsWith(parameter?.ToString(), StringComparison.OrdinalIgnoreCase) == true,
         StringConverterMethod.Contains => value?.Contains(parameter?.ToString()) == true,
         StringConverterMethod.ContainsIgnoreCase => value?.Contains(parameter?.ToString(), SpecialStringComparisons.IgnoreCase) == true,
         StringConverterMethod.ReplaceLineBreaks => value?.ReplaceLineBreaks(parameter?.ToString()),
         StringConverterMethod.TrimText => value == null ? null : Wording.TrimText(value, (int)parameter),
         StringConverterMethod.StringDistanceLevenshtein => value != null && parameter is string?StringDistance.Levenshtein(value, (string)parameter) : (int?)null,
             StringConverterMethod.StringDistanceDamerauLevenshtein => value != null && parameter is string?StringDistance.DamerauLevenshtein(value, (string)parameter) : (int?)null,
                 _ => throw Throw.InvalidEnumArgument(nameof(Method), Method)
     });
Пример #2
0
        static void Main(string[] args)
        {
            //A string is considered to be in title case if each word in the string is
            //either (a)capitalised(that is, only the first letter of the word is in upper case)
            //or(b) considered to be an exception and put entirely into lower case unless it is the
            //first word, which is always capitalised. Write a function that will convert a string
            //into title case, given an optional list of exceptions(minor words).
            //Вызов

            StringConversion sc     = new StringConversion();
            string           title1 = sc.ToTitleWords("a clash of KINGS");

            Console.WriteLine(title1);

            string title2 = sc.ToTitleWords("THE WIND IN THE WILLOWS");

            Console.WriteLine(title2);

            //You need to write a function AddOrChangeUrlParameter(url, keyValueParameter) that
            //can manipulate URL parameters. It should be able to add a parameter to an existing URL, but
            //also to change a parameter if it already exists.
            //Вызов

            ModifyUrl.AddOrChangeUrlParameter("www.example.com", "key=value");
            ModifyUrl.AddOrChangeUrlParameter("www.example.com?key=value", "key2=value2");
            ModifyUrl.AddOrChangeUrlParameter("www.example.com?key=oldValue", "key=newValue");

            //Implement the function UniqueInOrder which takes as argument a sequence and returns a list of
            //items without any elements with the same value next to each other and preserving
            //the original order of elements.
            //Вызов

            UniqueOrder <string, char> list1 = new UniqueOrder <string, char>();
            string s1 = list1.UniqueInOrder("AAAABBBCCDAABBB").ToString();
            string s2 = list1.UniqueInOrder("ABBCcAD").ToString();
            string s3 = list1.UniqueInOrder("12233").ToString();
            UniqueOrder <List <double>, double> list2 = new UniqueOrder <List <double>, double>();
            List <double> num = list2.UniqueInOrder(new List <double> {
                1.1, 2.2, 2.2, 3.3
            });

            //Complete the solution so that it reverses all of the words within the string passed in
            //Вызов

            Wording words = new Wording();
            string  text  = words.ReverseWords("The greatest victory is that which requires no battle");

            Console.WriteLine(text);

            //Write a function that returns the sum of two big numbers. The input numbers are strings and the function must return a string.
            Summing sum      = new Summing();
            string  sumTotal = sum.findSum("4567902", "245666");

            Console.WriteLine(sumTotal);
        }
Пример #3
0
        private void SaveRecord()
        {
            Wording current = (Wording)bs.Current;

            if (current.WordID == 0) // new wording created by this form
            {
                // insert into table
                DBAction.InsertWording(current);
                Dirty = false;
            }
            else if (Dirty) // existing study edited
            {
                DBAction.UpdateWording(current);
                Dirty = false;
            }
        }
Пример #4
0
        private void Application_DispatcherUnhandledException(object sender, DispatcherUnhandledExceptionEventArgs e)
        {
            e.Handled = true;
            string stackTrace = e.Exception.GetFullStackTrace();

            if (MainWindowViewModel.Singleton?.IsInitialized == true)
            {
                // If the main window is initialized, display the exception in the log view.
                MainWindowViewModel.Singleton.Log(new LogMessage
                                                  (
                                                      LogMessageType.Error,
                                                      new LogTextItem(stackTrace)
                                                  ));
            }
            else
            {
                // If the exception occurred before the main window is initialized, display a MessageBox and exit.
                MessageBoxes.Error(Wording.TrimText(stackTrace, 1000));
                Current.Shutdown();
            }
        }
Пример #5
0
 public SceneGame(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #6
0
 public SceneTitle(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #7
0
 public TerrainImage(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #8
0
 public static string GetWordingPath(Wording wording)
 {
     return(GetRootPath() + "/Wordings/" + wording.ImageUri);
 }
Пример #9
0
 public static string GetFashionResultPath(Wording wording)
 {
     return(rootPath + "res/Wordings/" + wording.ImageUri);
 }
Пример #10
0
 public Road(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #11
0
 public Religion(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #12
0
 public Culture(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #13
0
 public ScenarioMode(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #14
0
 public StartMode(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #15
0
 public GameMode(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #16
0
 public SceneEditGameWorld(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #17
0
 public static string GetWordingPath(Wording wording)
 {
     return(rootPath + "res/Wordings/" + wording.ImageUri);
 }
Пример #18
0
 public StrongholdType(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #19
0
 public Character(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #20
0
 public Force(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #21
0
 public static string GetFashionResultPath(Wording wording)
 {
     return(GetRootPath() + "/Wordings/" + wording.ImageUri);
 }
Пример #22
0
 public TileMapImageInfo(Wording w, string prefix) : base(w, prefix)
 {
 }
Пример #23
0
        public void BytecodeApi_Text_Wording()
        {
            string str = Create.AlphaNumericString(100);

            Assert.AreEqual(Wording.Rot13(Wording.Rot13(str)), str);
        }
Пример #24
0
 /// <summary>
 /// Converts the <see cref="TimeSpan" />? value to a human readable <see cref="string" /> based on the specified parameters used for the <see cref="Wording.FormatTimeSpan(TimeSpan, int, string)" /> method.
 /// </summary>
 /// <param name="value">The <see cref="TimeSpan" />? value to convert.</param>
 /// <returns>
 /// A <see cref="string" /> with the result of the conversion.
 /// </returns>
 public override string Convert(TimeSpan?value)
 {
     return(value == null ? null : Wording.FormatTimeSpan(value.Value, MaxElements, Separator));
 }