public override bool Equals(object obj) { if (obj == null) { return(false); } if (!(obj is String2)) { return(false); } String2 temp = obj as String2; if (Length != temp.Length) { return(false); } for (int i = 0; i < Length; i++) { if (this[i] != temp[i]) { return(false); } } return(true); }
public String2[] Split(String2 source) { if (source.Length < 1) { throw new ArgumentNullException("The length of split for source is short."); } if (Length < source.Length) { return(new String2[] { Copy() }); } int count = 0; int pre = 0; int peek = 0; String2LinkNode fin = new String2LinkNode(); String2LinkNode node = fin; while ((peek = IndexOf(source, pre)) > -1) { node = node.Add(SubString(pre, peek - pre)); pre = peek + source.Length; count++; } node = node.Add(SubString(pre, Length - pre)); String2[] ret = new String2[count + 1]; for (int i = 0; i < ret.Length; i++) { ret[i] = fin.Data; fin = fin.Next; } return(ret); }
public String2 Replace(String2 oldVal, String2 newVal) { if (oldVal.Length < 1) { throw new ArgumentNullException("Replace"); } if (Length < oldVal.Length) { return(Copy()); } int pre = 0; int peek = 0; String2LinkNode fin = new String2LinkNode(); String2LinkNode node = fin; while ((peek = IndexOf(oldVal, pre)) > -1) { node = node.Add(SubString(pre, peek - pre)); node = node.Add(newVal); pre = peek + oldVal.Length + 1; } node = node.Add(SubString(pre, Length - pre)); String2 ret = fin.Data; while (fin.Next != null) { fin = fin.Next; if (fin.IsNull()) { break; } ret += fin.Data; } return(ret); }
public String2[] Separate(String2 source) { int pos = IndexOf(source); if (pos < 0) { return(null); } return(new String2[] { SubString(0, pos).Trim(), SubString(pos + 1, Length - (pos + 1)).Trim() }); }
public int IndexLastOf(String2 source) { if (source.Length < 1) { return(-1); } if (Length < source.Length) { return(-1); } for (int i = Length - source.Length - 1; i >= 0; i--) { if (String2.CheckByte(data, i, source.ToBytes(), 0, source.Length)) { return(i); } } return(-1); }
public int IndexOf(String2 source, int index) { if (source.Length < 1) { return(-1); } if (Length < source.Length + index) { return(-1); } for (int i = index; i <= Length - source.Length; i++) { if (String2.CheckByte(data, i, source.ToBytes(), 0, source.Length)) { return(i); } } return(-1); }
public String2 ToBinary() { String2 ret = new String2(new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 }, Encode); for (int i = 0; i < 0x10; i++) { ret += String.Format(" 0x{0:X2}", i); } ret += CRLF; for (int i = 1, j = 0x00; i < Length; i++, j += 0x10) { --i; bool header = true; ret += CRLF; ret += String.Format("0x{0:X2} ", j); for (; i < Length && (i % 0x10 == 0 && !header); i++) { ret += String.Format("0x{0:X2}", this[i]); header = false; } } ret += CRLF; return(ret); }
public int IndexOf(String2 source) { return(IndexOf(source, 0)); }
public bool CheckEnd(String2 separator) { return(CheckEnd(separator.ToBytes())); }
public String2LinkNode Add(String2 data) { this.data = data; this.next = new String2LinkNode(); return(this.next); }