create some strings : String « Data Types « C# / C Sharp






create some strings

   

using System;

class MainClass {

    public static void Main() {
        
        string myString = "To be or not to be";
        string myString2 = "...\t that is the question";
        string myString3 = @"\t Friends, Romans, countrymen,
lend me your ears";

        // display the strings and their Length properties
        Console.WriteLine("myString = " + myString);
        Console.WriteLine("myString.Length = "
          + myString.Length);
        Console.WriteLine("myString2 = " + myString2);
        Console.WriteLine
         ("myString2.Length = " + myString2.Length);
        Console.WriteLine("myString3 = " + myString3);
        Console.WriteLine
          ("myString3.Length = " + myString3.Length);    
    }
}

   
    
  








Related examples in the same category

1.Is Palindrome
2.use the Concat() method to concatenate strings
3.use the addition operator (+) to concatenate strings
4.use the Copy() method to copy a string
5.use the Join() method to join strings
6.use the StartsWith() and EndsWith() methods to check if a string contains a specified substring at the start and end
7.use the Substring() method to retrieve substrings
8.use the Trim(), TrimStart(), and TrimEnd() methods to trim strings
9.use the PadLeft() and PadRight() methods to align strings
10.Decoding a Base64-encoded BinaryDecoding a Base64-encoded Binary
11.From Base 64 Decode StringFrom Base 64 Decode String
12.Using Strings
13.Creating Strings
14.string: Changing Charactersstring: Changing Characters
15.Removing CharactersRemoving Characters
16.Padding StringsPadding Strings
17.Joining StringsJoining Strings
18.Extracting SubstringsExtracting Substrings
19.String Concatenation 2String Concatenation 2
20.Substring demoSubstring demo
21.Trimming String SpacesTrimming String Spaces
22.Introduce stringIntroduce string
23.Some string operationsSome string operations
24.Display the digits of an integer using wordsDisplay the digits of an integer using words
25.Use Substring() 1Use Substring() 1
26.A string can control a switch statementA string can control a switch statement
27.Illustrates the use of strings 1Illustrates the use of strings 1
28.String ManipulationString Manipulation
29.String Manipulation ConcatenateString Manipulation Concatenate
30.String copyString copy
31.String Copy, End With and InsertString Copy, End With and Insert
32.Demonstrate escape sequences in strings. Demonstrate escape sequences in strings.
33.Demonstrate verbatim literal stringsDemonstrate verbatim literal strings
34.Display a string in reverse by using recursionDisplay a string in reverse by using recursion
35.Demonstrate Concat()Demonstrate Concat()
36.Demonstrate Concat() 2Demonstrate Concat() 2
37.Trimming and paddingTrimming and padding
38.Use Substring() 2Use Substring() 2
39.Strings: Regular ExpressionsStrings: Regular Expressions
40.String InterningString Interning
41.Lexical DetailsLexical Details