private _U_ LastIndexOf(_U_ searchvalue, _U_ fromindex) { if (searchvalue.IsNullNaNUndefined()) { return(_U_.NewNumber(-1)); } int index = -1; if (!fromindex.IsNullNaNUndefined()) { index = fromindex.ToInt(-1); } string value = searchvalue.ToString(); //if (index > this._value.Length - 1) // return _U_.NewNumber(-1); if (index >= 0 && index < this._value.Length) { return(_U_.NewNumber(this._value.LastIndexOf(value, index))); } else { return(_U_.NewNumber(this._value.LastIndexOf(value))); } }
private _U_ SetValue <T>(_U_ value, Action <T, int[]> callBack) { if (this._value == null) { return(_U_.Undefined()); } try { if (value.IsNullNaNUndefined()) { this._value = null; return(_U_.Undefined()); } var t = ToObject.ConvertTo <T>(value.ToString()); int[] array = new int[7]; array[0] = this._value.Value.Year; array[1] = this._value.Value.Month; array[2] = this._value.Value.Day; array[3] = this._value.Value.Hour; array[4] = this._value.Value.Minute; array[5] = this._value.Value.Second; array[6] = this._value.Value.Millisecond; this._value = null; callBack(t, array); this._value = new DateTime(array[0], array[1], array[2], array[3], array[4], array[5], array[6]); } catch { this._value = null; } return(_U_.Undefined()); }
private _U_ Split(_U_ separator, _U_ howmany) { var _array = new _Array(); if (separator.IsNullNaNUndefined()) { _array.__Add__(_U_.NewString(this._value)); return(_U_.New <_Array>(_array)); } string[] array = this._value.ToSplitStrings(separator.ToString()); string[] newArray = array; if (!howmany.IsNullNaNUndefined()) { int length = Math.Min(Math.Max(0, howmany.ToInt(0)), array.Length); if (length == 0) { return(_U_.New <_Array>()); } if (length < array.Length) { newArray = new string[length]; Array.Copy(array, 0, newArray, 0, length); } } foreach (var a in newArray) { _array.__Add__(_U_.NewString(a)); } return(_U_.New <_Array>(_array)); }
private _U_ StartsWith(_U_ uv, _U_ ignoreCase) { if (uv.IsNullNaNUndefined()) { return(_U_.NewBoolean(false)); } return(_U_.NewBoolean(this._value.StartsWith(uv.ToString(), ignoreCase.Value._Exists, null))); }
private _U_ Contains(_U_ uv) { if (uv.IsNullNaNUndefined()) { return(_U_.NewBoolean(false)); } return(_U_.NewBoolean(this._value.Contains(uv.ToString()))); }
public override void __Set__(string name, _U_ value) { switch (name) { case "length": int length = 0; if (int.TryParse(value.ToString(), out length)) { this.SetArrayLength(length); } else { throw new Exception(value.ToString() + " 不是有效的数组长度"); } break; default: base.__Set__(name, value); break; } }
public static DateTime ToDateTimeForUseVar(this _U_ v, out bool success) { DateTime _dt; success = false; if (DateTime.TryParse(v.ToString(), out _dt)) { success = true; } return(_dt); }
private _U_ Replace(_U_ substr, _U_ replacement) { if (!(substr.Value is _String)) { return(_U_.NewString(this._value)); } if (replacement.IsNullNaNUndefined()) { return(_U_.NewString(this._value)); } return(_U_.NewString(this._value.Replace(substr.ToString(), replacement.ToString()))); }
/// <summary> /// /// </summary> /// <param name="u"></param> /// <returns></returns> public static double?GetValueDoutle(this _U_ u) { if (u.Value is _Number) { return(u.Value as _Number); } else if (u.Value is _String) { double outValue = 0; if (double.TryParse(u.ToString(), out outValue)) { return(outValue); } } else if (u.Value is _Bool) { bool v = u.Value as _Bool; return(v == true ? 1 : 0); } return(null); }
private _U_ IndexOf(_U_ searchvalue, _U_ fromindex) { if (searchvalue.IsNullNaNUndefined()) { return(_U_.NewNumber(-1)); } int index = -1; if (!fromindex.IsNullNaNUndefined()) { index = fromindex.ToInt(-1); } string value = searchvalue.ToString(); if (index > this._value.Length - 1) { return(_U_.NewNumber(-1)); } return(_U_.NewNumber(this._value.IndexOf(value, Math.Max(0, index)))); }
public _U_ this[_U_ index] { get { return(this[index.ToString()]); } set { this[index.ToString()] = value; } }
/// <summary> /// 抛出异常 /// </summary> /// <param name="u"></param> /// <param name="line"></param> /// <returns></returns> protected void __throw__(_U_ u) { throw new Exception(u.ToString()); }