-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
56 lines (50 loc) · 1.61 KB
/
StringExtensions.cs
File metadata and controls
56 lines (50 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace X937
{
/// <summary>
/// Provides extra methods to the string class.
/// </summary>
public static class StringExtensions
{
/// <summary>
/// Returns the leftmost part of a string, of at most size characters.
/// </summary>
/// <param name="value">The string value to be trimmed.</param>
/// <param name="size">The maximum string size to return.</param>
/// <returns>A truncated string of no more than size characters.</returns>
public static string Left( this string value, int size )
{
if ( value == null )
{
return null;
}
if ( value.Length > size )
{
return value.Substring( 0, size );
}
return value;
}
/// <summary>
/// Returns the rightmost part of a string, of at most size characters.
/// </summary>
/// <param name="value">The string value to be trimmed.</param>
/// <param name="size">The maximum string size to return.</param>
/// <returns>A truncated string of no more than size characters.</returns>
public static string Right( this string value, int size )
{
if ( value == null )
{
return null;
}
if ( value.Length > size )
{
return value.Substring( value.Length - size, size );
}
return value;
}
}
}