-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
38 lines (34 loc) · 1.04 KB
/
StringExtensions.cs
File metadata and controls
38 lines (34 loc) · 1.04 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
using System;
using System.Collections.Generic;
using System.Text;
namespace OpenId.AspNet.Authentication
{
internal static class StringExtensions
{
public static string RemoveTrailingSlash(this string url)
{
if(url != null && url.EndsWith("/"))
url = url.Substring(0, url.Length - 1);
return url;
}
public static string ToBase64(this string str)
{
var b = Encoding.UTF8.GetBytes(str);
var result = Convert.ToBase64String(b);
return result;
}
public static string FromBase64(this string str)
{
var b = Convert.FromBase64String(str);
var result = Encoding.UTF8.GetString(b);
return result;
}
public static IEnumerable<string> Split(this string str, int chunkSize)
{
for(var i = 0; i < str.Length; i += chunkSize)
{
yield return str.Substring(i, Math.Min(chunkSize, str.Length - i));
}
}
}
}