本文整理汇总了C#中MutableString.Remove方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.Remove方法的具体用法?C# MutableString.Remove怎么用?C# MutableString.Remove使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.Remove方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReplaceSubstring
public static MutableString/*!*/ ReplaceSubstring(MutableString/*!*/ self,
[DefaultProtocol]int start, [DefaultProtocol]int charsToOverwrite, [DefaultProtocol, NotNull]MutableString/*!*/ value) {
if (charsToOverwrite < 0) {
throw RubyExceptions.CreateIndexError(String.Format("negative length {0}", charsToOverwrite));
}
if (System.Math.Abs(start) > self.Length) {
throw RubyExceptions.CreateIndexError(String.Format("index {0} out of string", start));
}
start = start < 0 ? start + self.Length : start;
if (charsToOverwrite <= value.Length) {
int insertIndex = start + charsToOverwrite;
int limit = charsToOverwrite;
if (insertIndex > self.Length) {
limit -= insertIndex - self.Length;
insertIndex = self.Length;
}
self.Replace(start, limit, value);
} else {
self.Replace(start, value.Length, value);
int pos = start + value.Length;
int charsToRemove = charsToOverwrite - value.Length;
int charsLeftInString = self.Length - pos;
self.Remove(pos, System.Math.Min(charsToRemove, charsLeftInString));
}
self.TaintBy(value);
return value;
}
示例2: RemoveSubstringInPlace
public static MutableString RemoveSubstringInPlace(MutableString/*!*/ self,
[DefaultProtocol]int start, [DefaultProtocol]int length) {
if (length < 0) {
return null;
}
if (!InInclusiveRangeNormalized(self, ref start)) {
return null;
}
if (start + length > self.Length) {
length = self.Length - start;
}
MutableString result = self.CreateInstance().Append(self, start, length).TaintBy(self);
self.Remove(start, length);
return result;
}
示例3: ReplaceCharacter
public static MutableString/*!*/ ReplaceCharacter(MutableString/*!*/ self,
[DefaultProtocol]int index, [DefaultProtocol, NotNull]MutableString/*!*/ value) {
index = index < 0 ? index + self.Length : index;
if (index < 0 || index >= self.Length) {
throw RubyExceptions.CreateIndexError(String.Format("index {0} out of string", index));
}
if (value.IsEmpty) {
self.Remove(index, 1).TaintBy(value);
return MutableString.CreateMutable();
}
self.Replace(index, 1, value).TaintBy(value);
return value;
}
示例4: SqueezeMutableString
private static MutableString SqueezeMutableString(MutableString/*!*/ str, MutableString[]/*!*/ ranges) {
// if squeezeAll is true then there should be no ranges, and vice versa
Assert.NotNull(str, ranges);
// convert the args into a map of characters to be squeezed (same algorithm as count)
BitArray map = null;
if (ranges.Length > 0) {
map = new RangeParser(ranges).Parse();
}
// Do the squeeze in place
int j = 1, k = 1;
while (j < str.Length) {
if (str.GetChar(j) == str.GetChar(j-1) && (ranges.Length == 0 || map.Get(str.GetChar(j)))) {
j++;
} else {
str.SetChar(k, str.GetChar(j));
j++; k++;
}
}
if (j > k) {
str.Remove(k, j - k);
}
// if not modified return null
return j == k ? null : str;
}
示例5: RemoveCharInPlace
public static object RemoveCharInPlace(RubyContext/*!*/ context, MutableString/*!*/ self,
[DefaultProtocol]int index) {
if (!InExclusiveRangeNormalized(self, ref index)) {
return null;
}
// TODO: optimize if the value is not read:
int result = self.PeekByte(index);
self.Remove(index, 1);
return result;
}
示例6: ChopInteral
private static MutableString/*!*/ ChopInteral(MutableString/*!*/ self) {
if (self.Length == 1 || self.GetChar(self.Length - 2) != '\r' || self.GetChar(self.Length - 1) != '\n') {
self.Remove(self.Length - 1, 1);
} else {
self.Remove(self.Length - 2, 2);
}
return self;
}
示例7: AppendBytes
// count == Int32.MaxValue means means no bound
public int AppendBytes(MutableString/*!*/ buffer, int count, bool preserveEndOfLines) {
ContractUtils.RequiresNotNull(buffer, "buffer");
ContractUtils.Requires(count >= 0, "count");
if (count == 0) {
return 0;
}
bool readAll = count == Int32.MaxValue;
buffer.SwitchToBytes();
int initialBufferSize = buffer.GetByteCount();
if (preserveEndOfLines) {
AppendRawBytes(buffer, count);
} else {
// allocate 3 more bytes at the end for a backstop and possible LF:
byte[] bytes = Utils.EmptyBytes;
int done = initialBufferSize;
bool eof;
do {
AppendRawBytes(buffer, readAll ? 1024 : count);
int end = buffer.GetByteCount();
int bytesRead = end - done;
if (bytesRead == 0) {
break;
}
eof = bytesRead < count;
buffer.EnsureCapacity(end + 3);
bytes = buffer.GetByteArray();
if (bytes[end - 1] == CR && PeekByte(0) == LF) {
ReadByte();
bytes[end++] = LF;
}
// insert backstop:
bytes[end] = CR;
bytes[end + 1] = LF;
int last = IndexOfCrLf(bytes, done);
count -= last - done;
done = last;
while (last < end) {
int next = IndexOfCrLf(bytes, last + 2);
int chunk = next - last - 1;
Buffer.BlockCopy(bytes, last + 1, bytes, done, chunk);
done += chunk;
count -= chunk;
last = next;
}
buffer.Remove(done);
} while (readAll || count > 0 && !eof);
}
if (readAll) {
buffer.TrimExcess();
}
return buffer.GetByteCount() - initialBufferSize;
}
示例8: ChopInteral
/*!*/
private static MutableString ChopInteral(MutableString/*!*/ self)
{
int length = self.GetCharCount();
if (length == 1 || self.GetChar(length - 2) != '\r' || self.GetChar(length - 1) != '\n') {
self.Remove(length - 1, 1);
} else {
self.Remove(length - 2, 2);
}
return self;
}
示例9: op_Remove_string
public void op_Remove_string(string expected,
string text,
string value)
{
var actual = new MutableString(text);
Assert.Same(actual, actual.Remove(value));
Assert.Equal(new MutableString(expected), actual);
}
示例10: op_Remove_int_int
public void op_Remove_int_int()
{
var expected = new MutableString("ample");
var actual = new MutableString("Example");
Assert.Same(actual, actual.Remove(0, 2));
Assert.Equal(expected, actual);
}