Exemplo n.º 1
0
        public static dynamic RandomInt(dynamic a, dynamic b)
        {
            int resultA = DynamicCast.ConvertToInt(a);
            int resultB = DynamicCast.ConvertToInt(b);

            return(resultA < resultB?Utils.RandomInt(resultA, resultB) : Utils.RandomInt(resultB, resultA));
        }
Exemplo n.º 2
0
        public static char GetLetterFromEnd(dynamic text, dynamic index)
        {
            string resultText  = ConvertToString(text);
            int    resultIndex = DynamicCast.ConvertToInt(index);

            if (string.IsNullOrEmpty(resultText) || resultIndex == 0)
            {
                return('\0');
            }

            return(resultText.Length - resultIndex > 0 ? resultText[resultText.Length - resultIndex] : '\0');
        }
Exemplo n.º 3
0
        public static string Substring(dynamic text, string where1, dynamic at1, string where2, dynamic at2)
        {
            string resultText = ConvertToString(text);
            int    at1Result  = DynamicCast.ConvertToInt(at1);
            int    at2Result  = DynamicCast.ConvertToInt(at2);

            var getAt = new Func <dynamic, int, int>((where, at) =>
            {
                switch (@where)
                {
                case "FROM_START":
                    at--;

                    break;

                case "FROM_END":
                    at = resultText.Length - at;

                    break;

                case "FIRST":
                    at = 0;

                    break;

                case "LAST":
                    at = resultText.Length - 1;

                    break;

                default:

                    throw new ApplicationException("Unhandled option (GetSubstring).");
                }

                return(at);
            });

            at1 = getAt(where1, at1Result);
            at2 = getAt(where2, at2Result) + 1;

            try
            {
                return(resultText.Substring(at1, at2 - at1));
            }
            catch (Exception e)
            {
                Log($"Can not get Substring({at1}, {at2 - at1}); for {resultText}.");

                return("");
            }
        }