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


C# Char.ThrowIfNull方法代码示例

本文整理汇总了C#中System.Char.ThrowIfNull方法的典型用法代码示例。如果您正苦于以下问题:C# Char.ThrowIfNull方法的具体用法?C# Char.ThrowIfNull怎么用?C# Char.ThrowIfNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Char的用法示例。


在下文中一共展示了Char.ThrowIfNull方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetBetween

        /// <summary>
        ///     Gets the part of the input string between the before and after value, starting at the given start index,
        ///     and ending after the specified number of characters.
        /// </summary>
        /// <exception cref="ArgumentNullException">The string can not be null.</exception>
        /// <exception cref="ArgumentNullException">value can not be null.</exception>
        /// <exception cref="ArgumentOutOfRangeException">The specified range is invalid.</exception>
        /// <param name="str">The input string.</param>
        /// <param name="before">The before value.</param>
        /// <param name="after">The after value.</param>
        /// <param name="startIndex">The start index of the string.</param>
        /// <param name="length">The length of the string, from the start index.</param>
        /// <returns>The part of the string between the before and after value.</returns>
        public static String GetBetween( this String str, Char before, Char after, Int32 startIndex, Int32 length )
        {
            // ReSharper disable once AccessToModifiedClosure
            str.ThrowIfNull( nameof( str ) );
            before.ThrowIfNull( nameof( before ) );
            after.ThrowIfNull( nameof( after ) );

            if ( startIndex < 0 || length < 0 || startIndex + length > str.Length )
                throw new ArgumentOutOfRangeException( "length", "The specified range is invalid." );

            str = str.Substring( startIndex, length );

            var beforeIndex = str.IndexOf( before );
            if ( beforeIndex < 0 )
                return String.Empty;

            var actualStartIndex = beforeIndex + 1;
            var afterIndex = str.IndexOf( after, actualStartIndex );
            return afterIndex < 0
                ? String.Empty
                : str.Substring( actualStartIndex, afterIndex - actualStartIndex );
        }
开发者ID:MannusEtten,项目名称:Extend,代码行数:35,代码来源:String.GetBetween.cs


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