本文整理汇总了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());
}
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例6: Empty
public static SObject Empty(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
return processor.CreateString("");
}
示例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;
}
示例8: toString
public static SObject toString(ScriptProcessor processor, SObject instance, SObject This, SObject[] parameters)
{
return processor.CreateString(LITERAL_OBJECT_STR);
}
示例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);
}
示例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;
}
示例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);
}
示例12: ToString
internal override SString ToString(ScriptProcessor processor)
{
return processor.CreateString(ToScriptSource());
}
示例13: TranslateString
private static SObject TranslateString(ScriptProcessor processor, string strIn)
{
return processor.CreateString(strIn);
}
示例14: ToString
internal override SString ToString(ScriptProcessor processor)
{
return processor.CreateString(LITERAL_OBJECT_STR);
}
示例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());
}