Exemple #1
0
        public AnsiString Insert(int startIndex, AnsiString value)
        {
            if (value == null) throw new ArgumentNullException();
            if ((startIndex < 0) || (startIndex > this.Length)) throw new ArgumentOutOfRangeException();

            int len = value.Length + this.Length;
            byte[] buffer = new byte[len];
            Array.Copy(value._array, 0, buffer, startIndex, value.Length);
            Array.Copy(this._array, 0, buffer, 0, startIndex);
            Array.Copy(this._array, this._array.Length - startIndex, buffer, startIndex + value.Length, this._array.Length - startIndex);
            return new AnsiString(buffer);
        }
Exemple #2
0
 /// <summary>按内容比较</summary>
 public bool Equals(AnsiString value)
 {
     if (value == null) return false;
     if (this.Length != value.Length) return false;
     return (AnsiString.Compare(this, value) == 0);
 }
Exemple #3
0
 /// <summary>从新克隆一份对象(不是复制一份引用)</summary>
 public static AnsiString Copy(AnsiString str)
 {
     byte[] buffer = new byte[str.Length];
     Array.Copy(str._array, buffer, str.Length);
     return new AnsiString(buffer);
 }
Exemple #4
0
 /// <summary>strcmp优化</summary>
 public bool EndsWith(AnsiString value)
 {
     if (value.Length > this.Length) return false;
     unsafe
     {
         fixed (byte* pA = &this._array[this.Length - value.Length])
         fixed (byte* pB = &value._array[0])
             if (CString.strncmp((sbyte*)pA, (sbyte*)pB, (uint)value.Length) == 0)
                 return true;
     }
     return false;
 }
Exemple #5
0
 /// <summary>按内容比较两个字符串是否相同</summary>
 public static int Compare(AnsiString strA, AnsiString strB)
 {
     if (strA.Length != strB.Length) return strA.Length - strB.Length;
     unsafe
     {
         fixed (byte* pA = &strA._array[0])
         fixed (byte* pB = &strB._array[0])
             return CString.memcmp(pA, pB, (uint)strA.Length);
     }
 }