本文整理汇总了C#中Regex.Trim方法的典型用法代码示例。如果您正苦于以下问题:C# Regex.Trim方法的具体用法?C# Regex.Trim怎么用?C# Regex.Trim使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Regex
的用法示例。
在下文中一共展示了Regex.Trim方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: eval
object eval(object o, string com){
com = com.Trim(new char[]{' ', ';'});
if (o == null){
string remainingCom = "";
object parsedCom = parseArg(com, out remainingCom);
if (parsedCom != null){
//Debug.Log(remainingCom);
return eval(parsedCom, remainingCom);
}
return "null";
}
if (com == ""){
return o;
}
//Debug.Log(com);
if (com.StartsWith("[")){//the command is to index at an array
string ind = new Regex(@"\[[\d]*\]").Match(com).Value;
int index = int.Parse(ind.Trim(new char[]{'[', ']'}));
System.Array arr = (System.Array)o;
object nobj = arr.GetValue(index);
string ncom = com.Substring(ind.Length);
return eval(nobj, ncom);
}
bool isType = (o is System.Type);
System.Type oType = isType ? ((System.Type)o) : o.GetType();
if (com.StartsWith(".")){//it's either a function or a property
com = com.Substring(1);//delete the period at the beginning
int periodIndex = com.IndexOf(".");
int bracketIndex = com.IndexOf("[");
int parenIndex = com.IndexOf("(");
int closeParenIndex = com.IndexOf(")");
if (parenIndex > -1){
int opened = 1;
for (int i = parenIndex + 1; i < com.Length && opened != 0; i++){
if (com[i] == '('){
opened ++;
} else if (com[i] == ')'){
opened --;
if (opened == 0){
closeParenIndex = i;
break;
}
}
}
}
//Debug.Log(com + " period: " + periodIndex + "; paren: " + parenIndex +
// "; cparen: " + closeParenIndex + "; len: " + com.Length);
if ((periodIndex <= parenIndex && periodIndex > -1) || parenIndex < 0){//it's a property
var props = new Dictionary<string, object>();
foreach(var prop in oType.GetProperties(BindingFlags.Instance|BindingFlags.Public|BindingFlags.Static)){
try {
props.Add(prop.Name, prop.GetValue(isType ? oType : o, null));
} catch {}
}
foreach(var prop in oType.GetFields()){
try {
props.Add(prop.Name, prop.GetValue(isType ? oType : o));
} catch {}
}
int fLength = 0;
if (periodIndex == -1 && bracketIndex == -1){
fLength = com.Length;
} else if (periodIndex == -1){
fLength = bracketIndex;
} else if (bracketIndex == -1){
fLength = periodIndex;
} else {
fLength = Mathf.Min(new int[]{bracketIndex, periodIndex});
}
string fCom = com.Substring(0, fLength);
if (props.ContainsKey(fCom)){
object nobj = props[fCom];
string ncom = com.Substring(fCom.Length);
return eval(nobj, ncom);
} else {
return "Unknown field or property";
//.........这里部分代码省略.........