mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-10 03:45:41 +00:00
✨ Add String.Split(int chunkSize)
This commit is contained in:
parent
9b5e02b5a1
commit
a699446112
@ -23,5 +23,5 @@ Below is a list of the number of extension methods written for a given type. Ove
|
|||||||
| `long` / `ulong` | `X10D` | 11 |
|
| `long` / `ulong` | `X10D` | 11 |
|
||||||
| `IList<T>` | `X10D` | 2 |
|
| `IList<T>` | `X10D` | 2 |
|
||||||
| `Random` | `X10D` | 2 |
|
| `Random` | `X10D` | 2 |
|
||||||
| `string` / `SecureString` | `X10D` | 7 |
|
| `string` / `SecureString` | `X10D` | 8 |
|
||||||
| `TimeSpan` | `X10D` | 1 |
|
| `TimeSpan` | `X10D` | 1 |
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#region Using Directives
|
#region Using Directives
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
using System.Security;
|
using System.Security;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
@ -118,6 +119,21 @@
|
|||||||
return builder.ToString();
|
return builder.ToString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Splits the <see cref="String"/> into chunks that are no greater than <paramref name="chunkSize"/> in length.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="str">The string to split.</param>
|
||||||
|
/// <param name="chunkSize">The maximum length of each string in the returned result.</param>
|
||||||
|
/// <returns>Returns an <see cref="IEnumerable{T}"/> containing <see cref="String"/> instances which are no
|
||||||
|
/// greater than <paramref name="chunkSize"/> in length.</returns>
|
||||||
|
public static IEnumerable<string> Split(this string str, int chunkSize)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < str.Length; i += chunkSize)
|
||||||
|
{
|
||||||
|
yield return str.Substring(i, Math.Min(chunkSize, str.Length - i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Converts a <see cref="String"/> to a <see cref="SecureString"/>.
|
/// Converts a <see cref="String"/> to a <see cref="SecureString"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user