<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Nvelope
{
    public static class StringExtensions
    {
        /// <remarks>This exists so that the compiler doesn't get confused and call the IEnumerable[char] version of Print
        /// on a string. Then you would get "(a,b)" from "ab".Print(), which is silly</remarks>
        public static string Print(this string s)
        {
            return s.ToStringN();
        }

        /// <summary>
        /// Returns a string array that contains the substrings in this string that are
        ///     delimited by elements of a specified string array. A parameter specifies
        ///     whether to return empty array elements.
        /// </summary>
        /// <param name="source">The source string, usually the object you're calling the Extension method on.</param>
        /// <param name="splitby">The token to split by.</param>
        public static string[] Split(this string source, string splitby)
        {            
            return source.Split(new string[] { splitby }, StringSplitOptions.None);
        }

        /// <summary>
        /// Returns an array of two strings that are separated by the specified string.
        /// </summary>
        /// <param name="source">The source string to be split into two items.</param>
        /// <param name="splitby">The string that the source is to be split by.</param>
        /// <returns>Two strings</returns>
        public static string[] SplitPair(this string source, string splitby)
        {
            string[] res = source.Split(splitby);

            if (res.Count() != 2)
                throw new Exception("The pair was not specified correctly. A pair can only be two items and must be separated by a specified string. In this case, the specified string was '" + splitby + "'.");

            return res;
        }

        public static string SentenceCase(this string sentence)
        {
            // matches the first sentence of a string, as well as subsequent sentences
            var r = new Regex(@"^\s*([a-z])",
                RegexOptions.ExplicitCapture | RegexOptions.Multiline);
            // MatchEvaluator delegate defines replacement of setence starts to uppercase
            return r.Replace(sentence, s => s.Value.ToUpper());

        }

        /// <summary>
        /// Assuming that your string in PowerShell is wrapped in double quotes, this will escape all of the 
        /// characters in your sentence so that you can have things like passwords with back-ticks, ampersands, single-quotes, etc.
        /// </summary>
        public static string EscapePowerShell(this string sentence)
        {
            sentence.Replace("`", "``");    // Escape back-ticks
            sentence.Replace("\"", "`\"");  // Escape double-quotes
            sentence.Replace("$", "`$");    // Escape Dollar sign
            sentence.Replace("&", "`&");    // Escape ampersand
            return sentence;
        }<commit_msg>String.Replace() returns a new string, so it was being used incorrectly before and needs to be assigned to a new string<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Nvelope
{
    public static class StringExtensions
    {
        /// <remarks>This exists so that the compiler doesn't get confused and call the IEnumerable[char] version of Print
        /// on a string. Then you would get "(a,b)" from "ab".Print(), which is silly</remarks>
        public static string Print(this string s)
        {
            return s.ToStringN();
        }

        /// <summary>
        /// Returns a string array that contains the substrings in this string that are
        ///     delimited by elements of a specified string array. A parameter specifies
        ///     whether to return empty array elements.
        /// </summary>
        /// <param name="source">The source string, usually the object you're calling the Extension method on.</param>
        /// <param name="splitby">The token to split by.</param>
        public static string[] Split(this string source, string splitby)
        {            
            return source.Split(new string[] { splitby }, StringSplitOptions.None);
        }

        /// <summary>
        /// Returns an array of two strings that are separated by the specified string.
        /// </summary>
        /// <param name="source">The source string to be split into two items.</param>
        /// <param name="splitby">The string that the source is to be split by.</param>
        /// <returns>Two strings</returns>
        public static string[] SplitPair(this string source, string splitby)
        {
            string[] res = source.Split(splitby);

            if (res.Count() != 2)
                throw new Exception("The pair was not specified correctly. A pair can only be two items and must be separated by a specified string. In this case, the specified string was '" + splitby + "'.");

            return res;
        }

        public static string SentenceCase(this string sentence)
        {
            // matches the first sentence of a string, as well as subsequent sentences
            var r = new Regex(@"^\s*([a-z])",
                RegexOptions.ExplicitCapture | RegexOptions.Multiline);
            // MatchEvaluator delegate defines replacement of setence starts to uppercase
            return r.Replace(sentence, s => s.Value.ToUpper());

        }

        /// <summary>
        /// Assuming that your string in PowerShell is wrapped in double quotes, this will escape all of the 
        /// characters in your sentence so that you can have things like passwords with back-ticks, ampersands, single-quotes, etc.
        /// </summary>
        public static string EscapePowerShell(this string sentence)
        {
            sentence = sentence.Replace("`", "``");    // Escape back-ticks
            sentence = sentence.Replace("\"", "`\"");  // Escape double-quotes
            sentence = sentence.Replace("$", "`$");    // Escape Dollar sign
            sentence = sentence.Replace("&", "`&");    // Escape ampersand
            return sentence;
        }
{'fraction_non_alphanumeric': 0.10536337670580768, 'fraction_numerical': 0.00031735956839098697, 'mean_word_length': 2.1515, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 41, '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': '4003188', 'n_tokens_mistral': 1554, 'n_tokens_neox': 1499, 'n_words': 616}