当前位置: 首页>>代码示例>>C#>>正文


C# MutableString.Replace方法代码示例

本文整理汇总了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;
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:10,代码来源:Html.cs

示例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;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:35,代码来源:MutableStringOps.cs

示例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;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:16,代码来源:MutableStringOps.cs

示例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);
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:15,代码来源:MutableStringOps.cs

示例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);
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:32,代码来源:MutableStringOps.cs

示例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;
        }
开发者ID:mscottford,项目名称:ironruby,代码行数:34,代码来源:MutableStringOps.cs

示例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);
            }
        }
开发者ID:rpattabi,项目名称:ironruby,代码行数:21,代码来源:FileOps.cs

示例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");
 }
开发者ID:KarlDirck,项目名称:cavity,代码行数:11,代码来源:JsonWriter.cs

示例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);
        }
开发者ID:,项目名称:,代码行数:18,代码来源:

示例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);
        }
开发者ID:,项目名称:,代码行数:30,代码来源:

示例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);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:9,代码来源:MutableString.Facts.cs

示例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));
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:6,代码来源:MutableString.Facts.cs

示例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);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:9,代码来源:MutableString.Facts.cs

示例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);
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:9,代码来源:MutableString.Facts.cs

示例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));
        }
开发者ID:KarlDirck,项目名称:cavity,代码行数:6,代码来源:MutableString.Facts.cs


注:本文中的MutableString.Replace方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。