-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathTrimStart.cs
37 lines (31 loc) · 1021 Bytes
/
TrimStart.cs
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
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace StringExtensions.Examples
{
[TestClass]
[TestCategory("Examples")]
public class TrimStartExample
{
[TestMethod]
public void Example1()
{
// Simply trim a prefix from the sample
string sample = "my test";
string trimmed = sample.TrimStart("my ", StringComparison.Ordinal);
Assert.AreEqual(trimmed, "test");
}
[TestMethod]
public void Example2()
{
// Trim only the first instance from the sample
string sample = "test test test";
string trimmed1 = sample.TrimStart("test ", StringComparison.Ordinal, 1);
string trimmed2 = sample.TrimStartOnce("test ", StringComparison.Ordinal);
Assert.AreEqual(trimmed1, "test test");
Assert.AreEqual(trimmed2, trimmed1);
}
}
}