本文整理汇总了C#中MutableString.Replace方法的典型用法代码示例。如果您正苦于以下问题:C# MutableString.Replace方法的具体用法?C# MutableString.Replace怎么用?C# MutableString.Replace使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MutableString
的用法示例。
在下文中一共展示了MutableString.Replace方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Decode
public static string Decode(string value)
{
var result = new MutableString(WebUtility.HtmlDecode(value));
foreach (var entity in _entities)
{
result.Replace(entity.Key, entity.Value);
}
return result;
}
示例2: 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;
}
示例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: ReplaceInPlace
private static MutableString ReplaceInPlace(RubyScope/*!*/ scope, MutableString/*!*/ self, RubyRegex/*!*/ pattern,
MutableString/*!*/ replacement, bool replaceAll) {
MutableString builder = replaceAll ?
ReplaceAll(scope, self, replacement, pattern) :
ReplaceFirst(scope, self, replacement, pattern);
// unsuccessful match:
if (builder == null) {
return null;
}
self.Replace(0, self.Length, builder);
return self.TaintBy(builder);
}
示例5: BlockReplaceInPlace
private static object BlockReplaceInPlace(RubyScope/*!*/ scope, BlockParam/*!*/ block, MutableString/*!*/ self,
RubyRegex/*!*/ pattern, bool replaceAll) {
object blockResult;
uint version = self.Version;
// prepare replacement in a builder:
MutableString builder;
if (replaceAll ?
BlockReplaceAll(scope, self, block, pattern, out blockResult, out builder) :
BlockReplaceFirst(scope, self, block, pattern, out blockResult, out builder)) {
// block jumped:
return blockResult;
}
// unsuccessful match:
if (builder == null) {
return null;
}
RequireNoVersionChange(version, self);
if (self.IsFrozen) {
throw new RuntimeError("string frozen");
}
// replace content of self with content of the builder:
self.Replace(0, self.Length, builder);
return self.TaintBy(builder);
}
示例6: BlockReplaceFirst
// returns true if block jumped
// "result" will be null if there is no successful match
private static bool BlockReplaceFirst(RubyScope/*!*/ scope, MutableString/*!*/ input, BlockParam/*!*/ block,
RubyRegex/*!*/ pattern, out object blockResult, out MutableString result) {
var matchScope = scope.GetInnerMostClosureScope();
MatchData match = RegexpOps.Match(scope, pattern, input);
if (match == null || !match.Success) {
result = null;
blockResult = null;
matchScope.CurrentMatch = null;
return false;
}
// copy upfront so that no modifications to the input string are included in the result:
result = input.Clone();
matchScope.CurrentMatch = match;
if (block.Yield(MutableString.Create(match.Value), out blockResult)) {
return true;
}
// resets the $~ scope variable to the last match (skipd if block jumped):
matchScope.CurrentMatch = match;
MutableString replacement = Protocols.ConvertToString(scope.RubyContext, blockResult);
result.TaintBy(replacement);
// Note - we don't interpolate special sequences like \1 in block return value
result.Replace(match.Index, match.Length, replacement);
blockResult = null;
return false;
}
示例7: AppendDirectoryName
private static void AppendDirectoryName(MutableString/*!*/ result, MutableString/*!*/ name) {
int resultLength = result.GetCharCount();
int i;
for (i = resultLength - 1; i >= 0; i--) {
if (!IsDirectorySeparator(result.GetChar(i))) {
break;
}
}
if (i == resultLength - 1) {
if (!IsDirectorySeparator(name.GetFirstChar())) {
result.Append(DirectorySeparatorChar);
}
result.Append(name);
} else if (IsDirectorySeparator(name.GetFirstChar())) {
result.Replace(i + 1, resultLength - i - 1, name);
} else {
result.Append(name);
}
}
示例8: Encode
private static string Encode(MutableString value)
{
return value
.Replace("\\", "\\\\")
.Replace("\"", "\\\"")
.Replace("\b", "\\b")
.Replace("\f", "\\f")
.Replace("\n", "\\n")
.Replace("\r", "\\r")
.Replace("\t", "\\t");
}
示例9: ReplaceInPlace
private static MutableString ReplaceInPlace(ConversionStorage<MutableString> toS, BinaryOpStorage hashDefault,
RubyScope/*!*/ scope, MutableString/*!*/ self, RubyRegex/*!*/ pattern,
Union<IDictionary<object, object>, MutableString>/*!*/ replacement, bool replaceAll) {
self.RequireNotFrozen();
MutableString builder = replaceAll ?
ReplaceAll(toS, hashDefault, scope, self, replacement, pattern) :
ReplaceFirst(toS, hashDefault, scope, self, replacement, pattern);
// unsuccessful match:
if (builder == null) {
return null;
}
self.Replace(0, self.Length, builder);
return self.TaintBy(builder);
}
示例10: BlockReplaceInPlace
private static object BlockReplaceInPlace(ConversionStorage<MutableString>/*!*/ tosConversion,
RubyScope/*!*/ scope, BlockParam/*!*/ block, MutableString/*!*/ self,
RubyRegex/*!*/ pattern, bool replaceAll) {
object blockResult;
self.RequireNotFrozen();
self.TrackChanges();
// prepare replacement in a builder:
MutableString builder;
if (replaceAll ?
BlockReplaceAll(tosConversion, scope, self, block, pattern, out blockResult, out builder) :
BlockReplaceFirst(tosConversion, scope, self, block, pattern, out blockResult, out builder)) {
// block jumped:
return blockResult;
}
// unsuccessful match:
if (builder == null) {
return null;
}
RequireNoVersionChange(self);
// replace content of self with content of the builder:
self.Replace(0, self.Length, builder);
return self.TaintBy(builder);
}
示例11: op_Replace_string_stringEmpty_whenDefault
public void op_Replace_string_stringEmpty_whenDefault()
{
var expected = new MutableString();
var actual = new MutableString();
Assert.Same(actual, actual.Replace("example", string.Empty));
Assert.Equal(expected, actual);
}
示例12: op_Replace_string_stringEmpty_int_int_whenDefault
public void op_Replace_string_stringEmpty_int_int_whenDefault()
{
var obj = new MutableString();
Assert.Throws<ArgumentOutOfRangeException>(() => obj.Replace("example", string.Empty, 0, 1));
}
示例13: op_Replace_string_stringEmpty_int_int
public void op_Replace_string_stringEmpty_int_int()
{
var expected = new MutableString("Ex");
var actual = new MutableString("Example");
Assert.Same(actual, actual.Replace("ample", string.Empty, 0, 7));
Assert.Equal(expected, actual);
}
示例14: op_Replace_char_char_whenDefault
public void op_Replace_char_char_whenDefault()
{
var expected = new MutableString();
var actual = new MutableString();
Assert.Same(actual, actual.Replace('.', '-'));
Assert.Equal(expected, actual);
}
示例15: op_Replace_char_char_int_int_whenDefault
public void op_Replace_char_char_int_int_whenDefault()
{
var obj = new MutableString();
Assert.Throws<ArgumentOutOfRangeException>(() => obj.Replace('.', '-', 0, 1));
}