-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathStringBuildOut.cs
53 lines (47 loc) · 2.8 KB
/
StringBuildOut.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using Microsoft.SqlServer.Server;
namespace MySQLCLRFunctions
{
public static class StringBuildOut
{
/***************************************************************************************************************************************************************************************************
*
* For building lines in a loop.
*
**************************************************************************************************************************************************************************************/
[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, IsPrecise = true)]
public static string AppendWithSeparator(string input, string newfield, string sep)
{
if (StringTest.IsNullOrWhiteSpaceOrEmpty(newfield)) return input;
if (StringTest.IsNullOrWhiteSpaceOrEmpty(sep)) sep = ", ";
// No sense adding the same value
if (input?.Length == 0) return newfield;
else return input + sep + newfield;
}
/***************************************************************************************************************************************************************************************************
*
* For building CSV lines in a loop.
*
**************************************************************************************************************************************************************************************/
[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, IsPrecise = true)]
public static string AppendWithComma(string input, string newfield)
{
if (StringTest.IsNullOrWhiteSpaceOrEmpty(newfield)) return input;
// No sense adding the same value
if (input?.Length == 0) return newfield;
else return input + ", " + newfield;
}
/***************************************************************************************************************************************************************************************************
*
* For building TSV lines in a loop.
*
**************************************************************************************************************************************************************************************/
[SqlFunction(DataAccess = DataAccessKind.None, IsDeterministic = true, IsPrecise = true)]
public static string AppendWithTab(string input, string newfield)
{
if (StringTest.IsNullOrWhiteSpaceOrEmpty(newfield)) return input;
// No sense adding the same value
if (input?.Length == 0) return newfield;
else return input + '\t' + newfield;
}
}
}