<commit_before>csharp-extensions
=================


#### string extensions:

```c#
var s = "";
if (s.IsNullOrEmpty()) { /**/ }
if (s.IsNullOrWhiteSpace()) { /**/ }
```

```c#
// some string that could be null/empty/whitespace
string s = null; // or "value"
string text = "default";
if (!s.IsNullOrWhiteSpace()) text = s.Trim();
// fluent code by avoiding comparison
string text = s.OrEmpty().Trim(); // "" when s is null/empty/whitespace
string text = s.Or("default").Trim(); // "default" when s is null/empty/whitespace
```

```c#
// html-en/decode, url-en/decode
string s = "";
string htmlencoded = s.HtmlEncode();
string htmldecoded = s.HtmlDecode();
string urlencoded = s.UrlEncode();
string urldecoded = s.UrlDecode();
```

```c#
// "".format() instead of string.Format()
"{0} is a {1}".format("this", "test");
// parameter index is optional
"{} is a {}".format("this", "test");
"{} is a {1}".format("this", "test"); // mixing is ok
// parameter meta is allowed
"The name is {0}. {first} {last}.".format(lastName, firstName, lastName); // adding arg meta is ok
"The name is {last}. {first} {last}.".format(lastName, firstName); // bit intelligent about repeating arg meta
```

```c#
// bool try-parse string with default value
bool b = "".ToBool(defaultValue: true);
// b: true
```

```c#
// munge a password
string[] munged = "password".Munge().ToArray();
// munged: { "<PASSWORD>" }
string[] munged = "ai".Munge().ToArray();
// munged: { "@1", "@!" }
// unmunge a password
string[] unmunged = "<PASSWORD>".Unmunge().ToArray();
// unmunged: { "password" }
string[] unmunged = "@1".Unmunge().ToArray();
// unmunged: { "ai", "al" }
```

```c#
// scrabble characters of word (like the game)
var word = "on";
var scrabbled = word.Scrabble();
// scrabbled: { "o", "on", "n", "no" }
```

```c#
// parse a string in UTC format as DateTime
DateTime date = "2013-04-01T03:42:14-04:00".ParseAsUtc();
// date: 4/1/2013 7:42:14 AM, Kind: Utc
```

```c#
// convert a string to title case
string result = "war and peace".ToTitleCase();
// result: "War And Peace"
```

```c#
// split a csv string
string result = "a,b;c|d".SplitCsv();
// result: [ "a", "b", "c", "d" ]
```

```c#
// substring till end
string result = "this is a test".SubstringTillEnd(4);
// result: "test"
```

```c#
// substring by specifying start index and end index
string result = "this".SubstringByIndex(1, 3);
// result: "hi"
```
<commit_msg>readme: Fix typo for SplitCsv()<commit_after>csharp-extensions
=================


#### string extensions:

```c#
var s = "";
if (s.IsNullOrEmpty()) { /**/ }
if (s.IsNullOrWhiteSpace()) { /**/ }
```

```c#
// some string that could be null/empty/whitespace
string s = null; // or "value"
string text = "default";
if (!s.IsNullOrWhiteSpace()) text = s.Trim();
// fluent code by avoiding comparison
string text = s.OrEmpty().Trim(); // "" when s is null/empty/whitespace
string text = s.Or("default").Trim(); // "default" when s is null/empty/whitespace
```

```c#
// html-en/decode, url-en/decode
string s = "";
string htmlencoded = s.HtmlEncode();
string htmldecoded = s.HtmlDecode();
string urlencoded = s.UrlEncode();
string urldecoded = s.UrlDecode();
```

```c#
// "".format() instead of string.Format()
"{0} is a {1}".format("this", "test");
// parameter index is optional
"{} is a {}".format("this", "test");
"{} is a {1}".format("this", "test"); // mixing is ok
// parameter meta is allowed
"The name is {0}. {first} {last}.".format(lastName, firstName, lastName); // adding arg meta is ok
"The name is {last}. {first} {last}.".format(lastName, firstName); // bit intelligent about repeating arg meta
```

```c#
// bool try-parse string with default value
bool b = "".ToBool(defaultValue: true);
// b: true
```

```c#
// munge a password
string[] munged = "password".Munge().ToArray();
// munged: { "<PASSWORD>" }
string[] munged = "ai".Munge().ToArray();
// munged: { "@1", "@!" }
// unmunge a password
string[] unmunged = "<PASSWORD>".Unmunge().ToArray();
// unmunged: { "password" }
string[] unmunged = "@1".Unmunge().ToArray();
// unmunged: { "ai", "al" }
```

```c#
// scrabble characters of word (like the game)
var word = "on";
var scrabbled = word.Scrabble();
// scrabbled: { "o", "on", "n", "no" }
```

```c#
// parse a string in UTC format as DateTime
DateTime date = "2013-04-01T03:42:14-04:00".ParseAsUtc();
// date: 4/1/2013 7:42:14 AM, Kind: Utc
```

```c#
// convert a string to title case
string result = "war and peace".ToTitleCase();
// result: "War And Peace"
```

```c#
// split a csv string
string[] result = "a,b;c|d".SplitCsv().ToArray();
// result: [ "a", "b", "c", "d" ]
```

```c#
// substring till end
string result = "this is a test".SubstringTillEnd(4);
// result: "test"
```

```c#
// substring by specifying start index and end index
string result = "this".SubstringByIndex(1, 3);
// result: "hi"
```

{'fraction_non_alphanumeric': 0.22937293729372937, 'fraction_numerical': 0.015676567656765675, 'mean_word_length': 3.9682377049180326, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '389198', 'n_tokens_mistral': 1814, 'n_tokens_neox': 1718, 'n_words': 514}