本文整理汇总了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 );
}