Example #1
0
 public void TestFrFRUpperCaseCharacter()
 {
     char ch = 'G';
     char expectedChar = ch;
     TextInfo textInfo = new CultureInfo("fr-FR").TextInfo;
     char actualChar = textInfo.ToUpper(ch);
     Assert.Equal(expectedChar, actualChar);
 }
Example #2
0
        public void TestTrTRUppercaseCharacter()
        {
            char ch = '\u0130';
            char expectedChar = ch;
            TextInfo textInfo = new CultureInfo("tr-TR").TextInfo;

            char actualChar = textInfo.ToUpper(ch);
            Assert.Equal(expectedChar, actualChar);
        }
Example #3
0
        public void TestFrFRStringWithSymbols()
        {
            string strA = "Hello\n\0World\u0009!";
            string ActualResult;

            TextInfo textInfo = new CultureInfo("fr-FR").TextInfo;
            ActualResult = textInfo.ToUpper(strA);
            Assert.Equal("HELLO\n\0WORLD\t!", ActualResult);
        }
Example #4
0
        public void TestEnUSLowercaseCharacter()
        {
            char ch = 'a';
            char expectedChar = 'A';
            TextInfo textInfo = new CultureInfo("en-US").TextInfo;

            char actualChar = textInfo.ToUpper(ch);
            Assert.Equal(expectedChar, actualChar);
        }
Example #5
0
        public void TestEmptyString()
        {
            string strA = string.Empty;
            string ActualResult;

            TextInfo textInfo = new CultureInfo("en-US").TextInfo;
            ActualResult = textInfo.ToUpper(strA);
            Assert.Equal(string.Empty, ActualResult);
        }
Example #6
0
        public void TestTrTRNormalString()
        {
            string strA = "H\u0131!";
            string ActualResult;

            TextInfo textInfo = new CultureInfo("tr-TR").TextInfo;

            ActualResult = textInfo.ToUpper(strA);
            Assert.Equal("HI!", ActualResult);
        }
Example #7
0
        public void TestFrFRNormalString()
        {
            string strA = "HelloWorld!";
            string ActualResult;

            TextInfo textInfo = new CultureInfo("fr-FR").TextInfo;

            ActualResult = textInfo.ToUpper(strA);
            Assert.Equal("HELLOWORLD!", ActualResult);
        }
Example #8
0
        public void TestNonAlphabeticCharacter()
        {
            for (int i = 0; i <= 9; i++)
            {
                char ch = Convert.ToChar(i);
                char expectedChar = ch;
                TextInfo textInfo = new CultureInfo("en-US").TextInfo;

                char actualChar = textInfo.ToUpper(ch);
                Assert.Equal(expectedChar, actualChar);
            }
        }
        public string_advanced_examples()
        {
            //escape sequences
            string tab = "This is a\t tab.";
            string charLiterals = "This is a\' break.";
            string newLine = "This is a\n new line.";
            string backslash = "This is a \\ backslash because otherwise it wouldn't work properly and it would throw an error.";
            string backspace = "this is a backspace \b";
            string carriageReturn = "This is a \r carriage return";

            /*-----------------------------------------------------
            * All escape sequences
            * ---------------------------------------------------*/
            //\' - single quote, needed for character literals
            //\" - double quote, needed for string literals
            //\\ - backslash
            //\0 - Unicode character 0 (ASCII)
            //\a - Alert (character 7)
            //\b - Backspace (character 8)
            //\f - Form feed (character 12)
            //\n - New line (character 10)
            //\r - Carriage return (character 13)
            //\t - Horizontal tab (character 9)
            //\v - Vertical quote (character 11)
            //\uxxxx - Unicode escape sequence for character with hex value xxxx
            //\xn[n][n][n] - Unicode escape sequence for character with hex value nnnn (variable length version of \uxxxx)
            //\Uxxxxxxxx - Unicode escape sequence for character with hex value xxxxxxxx (for generating surrogates)

            //verbatims
            //In a verbatim string literal, the characters between the delimiters are interpreted verbatim, the only exception being a quote-escape-sequence. In particular, simple escape sequences and hexadecimal and Unicode escape sequences are not processed in verbatim string literals. A verbatim string literal may span multiple lines.
            string verbatim = @"And she said, 'Johnny knows the world is cruel but he loves 'it' anyways'.";
            Console.WriteLine(verbatim);
            //verbatims appear "as-is", meaning it is cleaner and easier to program. You don't need to use escape sequences all over the place.

            //case manipulation
            Console.WriteLine("\nBegin String case manipulation\n");
            string monkey = "monKEYs aRE WILD animals.";
            Console.WriteLine("\"{0}\" string lower case: {1}", monkey, monkey.ToLower());// this should take the string and put everything in lower case.
            Console.WriteLine("\"{0}\" string upper case: {1}", monkey, monkey.ToUpper());// this should take the string and put everything in upper case.

            TextInfo ti = new CultureInfo("en-US", false).TextInfo;
            Console.WriteLine("\"{0}\" textinfo upper case: {1}", monkey, ti.ToUpper(monkey));// this should take the string and put everything in upper case.
            Console.WriteLine("\"{0}\" textinfo lower case: {1}", monkey, ti.ToLower(monkey));// this should take the string and put everything in lower case.
            Console.WriteLine("\"{0}\" textinfo titled case: {1}", monkey, ti.ToTitleCase(monkey));// this should take the string and put everything in titled case.

            string bubby = "   asdf a sdfsd  sd  f d  f f     ";
            bubby = bubby.Trim();// removes all white spaces and non-alphabetic characters.
            Console.WriteLine("The new and improved bubby is: " + bubby);

            //i have no idea what these do.
            bubby = bubby.PadLeft(17, 'a');
            Console.WriteLine(bubby);
            bubby = bubby.PadRight(5, 'u');
            Console.WriteLine(bubby);

            string attack = "Yummy people are awkward to socalize with.";
            Console.WriteLine("Length of attack var is " + attack.Length);//this returns the number of characters of the string. Cannot be invoked like Java.

            bool check = true;

            while (check == true)
            {

                if (attack.Contains(':') || attack.Contains('@') || attack.Contains('.') || attack.Contains('='))
                {
                    Console.WriteLine("A SQL injection attempt has been detected. Cleaning input now.");
                    attack = attack.Replace('.', ' ');
                    attack = attack.Replace('@', ' ');
                    attack = attack.Replace(':', ' ');
                    attack = attack.Replace('=', ' ');

                    check = true;//this type of logic could be used to check for invalid input that might be used in a SQL injection attack.
                }
                else
                {
                    Console.WriteLine("SQL injection check completed. As you were.");
                    check = false;
                }

            }

            //concationating strings
            string hank = "Hank Hill";
            string peggy = "Peggy Hill";
            string married = "are married.";
            Console.WriteLine(hank + " and " + peggy + " " + married);
            //similar way to do this:
            Console.WriteLine("{0} and {1} {2}", hank, peggy, married);// don't have to type as many pluses and "" things.

            //concatination is slow. Use the String Builder class for larger strings.
            StringBuilder sbuild = new StringBuilder();
            sbuild.Append(hank);
            sbuild.Append(" and ");
            sbuild.Append(peggy);
            sbuild.Append(" ");
            sbuild.Append(married);

            Console.WriteLine(sbuild);
            //although there is no output difference this method is more efficient.
        }
Example #10
0
        // regex match evaluator for changing case
        private string MatchEvalChangeCase( Match match )
        {
            TextInfo ti = new CultureInfo( "en" ).TextInfo;

              if     ( itmChangeCaseUppercase.Checked ) return ti.ToUpper( match.Groups[1].Value );
              else if( itmChangeCaseLowercase.Checked ) return ti.ToLower( match.Groups[1].Value );
              else if( itmChangeCaseTitlecase.Checked ) return ti.ToTitleCase( match.Groups[1].Value.ToLower() );
              else                                      return match.Groups[1].Value;
        }
Example #11
0
        public void TestTrTRStringWithSymbols()
        {
            string strA = "H\u0131\n\0Hi\u0009!";
            string ActualResult;

            TextInfo textInfo = new CultureInfo("tr-TR").TextInfo;
            ActualResult = textInfo.ToUpper(strA);
            Assert.Equal("HI\n\0H\u0130\t!", ActualResult);
        }
Example #12
0
        public void TestTrTRNullString()
        {
            TextInfo textInfoUS = new CultureInfo("tr-TR").TextInfo;
            string str = null;

            Assert.Throws<ArgumentNullException>(() =>
            {
                textInfoUS.ToUpper(str);
            });
        }