当前位置: 首页>>代码示例>>C#>>正文


C# ScriptProcessor.CreateString方法代码示例

本文整理汇总了C#中ScriptProcessor.CreateString方法的典型用法代码示例。如果您正苦于以下问题:C# ScriptProcessor.CreateString方法的具体用法?C# ScriptProcessor.CreateString怎么用?C# ScriptProcessor.CreateString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ScriptProcessor的用法示例。


在下文中一共展示了ScriptProcessor.CreateString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CharAt

        public static SObject CharAt(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var str = (instance as SString).Value;

            if (str == "")
                return processor.CreateString("");

            if (TypeContract.Ensure(parameters, typeof(SNumber)))
            {
                var index = (int)(parameters[0] as SNumber).Value;

                if (index < 0 || index >= str.Length)
                    return processor.CreateString("");

                return processor.CreateString(str[index].ToString());
            }
            else
            {
                return processor.CreateString(str[0].ToString());
            }
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:21,代码来源:StringPrototype.cs

示例2: constructor

        private static SObject constructor(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var obj = (SError)instance;

            if (parameters.Length > 0)
            {
                SString message;

                if (parameters[0] is SString)
                    message = (SString)parameters[0];
                else
                    message = parameters[0].ToString(processor);

                obj.Members[MEMBER_NAME_MESSAGE].Data = message;
            }

            if (parameters.Length > 1)
            {
                SString errorType;

                if (parameters[1] is SString)
                    errorType = (SString)parameters[1];
                else
                    errorType = parameters[1].ToString(processor);

                obj.Members[MEMBER_NAME_TYPE].Data = errorType;
            }
            else
            {
                obj.Members[MEMBER_NAME_TYPE].Data = processor.CreateString("UserError");
            }

            if (parameters.Length > 2)
            {
                SNumber errorLine;

                if (parameters[2] is SNumber)
                    errorLine = (SNumber)parameters[2];
                else
                    errorLine = parameters[2].ToNumber(processor);

                obj.Members[MEMBER_NAME_LINE].Data = errorLine;
            }
            else
            {
                obj.Members[MEMBER_NAME_LINE].Data = processor.CreateNumber(-1);
            }

            return obj;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:50,代码来源:ErrorPrototype.cs

示例3: Concat

        public static SObject Concat(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (parameters.Length > 0)
            {
                var str = instance as SString;

                string result = str.Value;
                foreach (var param in parameters)
                {
                    string concatStr = param.ToString(processor).Value;
                    result += concatStr;
                }

                return processor.CreateString(result);
            }

            return processor.CreateString((instance as SString).Value);
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:18,代码来源:StringPrototype.cs

示例4: Remove

        public static SObject Remove(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (TypeContract.Ensure(parameters, new[] { typeof(SNumber), typeof(SNumber) }))
            {
                var str = (instance as SString).Value;
                var start = (int)(parameters[0] as SNumber).Value;
                var length = (int)(parameters[1] as SNumber).Value;

                if (start < 0)
                    start = 0;
                if (start > str.Length)
                    return processor.CreateString(str);

                if (length <= 0)
                    return processor.CreateString(str);
                if (length + start > str.Length)
                    length = str.Length - start;

                return processor.CreateString(str.Remove(start, length));
            }
            if (TypeContract.Ensure(parameters, typeof(SNumber)))
            {
                var str = (instance as SString).Value;
                var start = (int)(parameters[0] as SNumber).Value;
                
                if (start < 0)
                    start = 0;
                if (start > str.Length)
                    return processor.CreateString(str);

                return processor.CreateString(str.Remove(start));
            }

            return processor.Undefined;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:35,代码来源:StringPrototype.cs

示例5: TrimEnd

        public static SObject TrimEnd(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            string str = (instance as SString).Value;
            string[] trimChars = { " " };

            if (TypeContract.Ensure(parameters, typeof(SArray)))
            {
                trimChars = (parameters[0] as SArray).ArrayMembers.Select(m => m.ToString(processor).Value).ToArray();
            }
            else if (TypeContract.Ensure(parameters, typeof(SString)))
            {
                trimChars = new[] { (parameters[0] as SString).Value };
            }

            foreach (var trimChar in trimChars)
            {
                while (str.EndsWith(trimChar))
                    str = str.Remove(str.Length - trimChar.Length);
            }

            return processor.CreateString(str);
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:22,代码来源:StringPrototype.cs

示例6: Empty

 public static SObject Empty(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
 {
     return processor.CreateString("");
 }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:4,代码来源:StringPrototype.cs

示例7: Slice

        public static SObject Slice(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (TypeContract.Ensure(parameters, new[] { typeof(SNumber), typeof(SNumber) }))
            {
                var str = (instance as SString).Value;
                var sliceBegin = (int)(parameters[0] as SNumber).Value;
                var sliceEnd = (int)(parameters[1] as SNumber).Value;

                if (sliceBegin < 0)
                    sliceBegin += str.Length;
                if (sliceBegin < 0)
                    sliceBegin = 0;
                if (sliceBegin > str.Length)
                    return processor.CreateString("");

                if (sliceEnd < 0)
                    sliceEnd += str.Length;
                if (sliceEnd < 0)
                    sliceEnd = 0;
                if (sliceEnd > str.Length)
                    sliceEnd = str.Length;

                return processor.CreateString(str.Substring(sliceBegin, sliceEnd - sliceBegin));
            }
            if (TypeContract.Ensure(parameters, typeof(SNumber)))
            {
                var str = (instance as SString).Value;
                var sliceBegin = (int)(parameters[0] as SNumber).Value;

                if (sliceBegin < 0)
                    sliceBegin += str.Length;
                if (sliceBegin < 0)
                    sliceBegin = 0;
                if (sliceBegin > str.Length)
                    return processor.CreateString("");

                return processor.CreateString(str.Substring(sliceBegin));
            }

            return processor.Undefined;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:41,代码来源:StringPrototype.cs

示例8: toString

 public static SObject toString(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
 {
     return processor.CreateString(LITERAL_OBJECT_STR);
 }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:4,代码来源:ObjectPrototype.cs

示例9: Repeat

        public static SObject Repeat(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (TypeContract.Ensure(parameters, typeof(SNumber)))
            {
                var repeatStr = (instance as SString).Value;
                var times = (int)(parameters[0] as SNumber).Value;
                var str = "";

                for (int i = 0; i < times; i++)
                    str += repeatStr;

                return processor.CreateString(str);
            }

            return processor.CreateString((instance as SString).Value);
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:16,代码来源:StringPrototype.cs

示例10: Replace

        public static SObject Replace(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            if (TypeContract.Ensure(parameters, new[] { typeof(SString), typeof(SString) }))
            {
                var str = (instance as SString).Value;
                var replace = (parameters[0] as SString).Value;
                var with = (parameters[1] as SString).Value;

                if (string.IsNullOrWhiteSpace(replace))
                    return processor.CreateString(str);

                return processor.CreateString(str.Replace(replace, with));
            }

            return processor.Undefined;
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:16,代码来源:StringPrototype.cs

示例11: PadStart

        public static SObject PadStart(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            var str = (instance as SString).Value;
            int totalLength = 0;
            var padStr = " ";
            string newPadded = "";

            if (TypeContract.Ensure(parameters, new[] { typeof(SNumber), typeof(SString) }))
            {
                totalLength = (int)(parameters[0] as SNumber).Value;
                padStr = (parameters[1] as SString).Value;
            }
            if (TypeContract.Ensure(parameters, typeof(SNumber)))
            {
                totalLength = (int)(parameters[0] as SNumber).Value;
            }

            if (padStr == "" || totalLength <= str.Length)
                return processor.CreateString(str);

            while (newPadded.Length + str.Length < totalLength)
                newPadded += padStr;

            if (newPadded.Length + str.Length > totalLength)
                newPadded = newPadded.Remove(totalLength - str.Length);

            str = newPadded + str;

            return processor.CreateString(str);
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:30,代码来源:StringPrototype.cs

示例12: ToString

 internal override SString ToString(ScriptProcessor processor)
 {
     return processor.CreateString(ToScriptSource());
 }
开发者ID:Aragas,项目名称:Pokemon3D-1,代码行数:4,代码来源:SArray.cs

示例13: TranslateString

 private static SObject TranslateString(ScriptProcessor processor, string strIn)
 {
     return processor.CreateString(strIn);
 }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:4,代码来源:ScriptInAdapter.cs

示例14: ToString

 internal override SString ToString(ScriptProcessor processor)
 {
     return processor.CreateString(LITERAL_OBJECT_STR);
 }
开发者ID:Aragas,项目名称:Pokemon3D-1,代码行数:4,代码来源:SProtoObject.cs

示例15: Split

        public static SObject Split(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
        {
            int limit = -1;
            string[] split;
            string[] delimiters;
            string str = (instance as SString).Value;

            if (TypeContract.Ensure(parameters, new[] { typeof(SArray), typeof(SNumber) }))
            {
                delimiters = (parameters[0] as SArray).ArrayMembers.Select(m => m.ToString(processor).Value).ToArray();
                limit = (int)(parameters[1] as SNumber).Value;
            }
            else if (TypeContract.Ensure(parameters, typeof(SArray)))
            {
                delimiters = (parameters[0] as SArray).ArrayMembers.Select(m => m.ToString(processor).Value).ToArray();
            }
            else if (TypeContract.Ensure(parameters, new[] { typeof(SString), typeof(SNumber) }))
            {
                delimiters = new[] { (parameters[0] as SString).Value };
                limit = (int)(parameters[1] as SNumber).Value;
            }
            else if (TypeContract.Ensure(parameters, typeof(SString)))
            {
                delimiters = new[] { (parameters[0] as SString).Value };
            }
            else
            {
                return processor.CreateArray(new[] { processor.CreateString(str) });
            }

            split = str.Split(delimiters, StringSplitOptions.None);
            if (limit >= 0 && split.Length > limit)
            {
                var result = new string[limit];
                Array.Copy(split, result, limit);
                split = result;
            }

            return processor.CreateArray(split.Select(m => processor.CreateString(m)).ToArray());
        }
开发者ID:nilllzz,项目名称:Pokemon3D,代码行数:40,代码来源:StringPrototype.cs


注:本文中的ScriptProcessor.CreateString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。