Some string operations : String « Data Types « C# / C Sharp

Home
C# / C Sharp
1.2D Graphics
2.Class Interface
3.Collections Data Structure
4.Components
5.Data Types
6.Database ADO.net
7.Design Patterns
8.Development Class
9.Event
10.File Stream
11.Generics
12.GUI Windows Form
13.Language Basics
14.LINQ
15.Network
16.Office
17.Reflection
18.Regular Expressions
19.Security
20.Services Event
21.Thread
22.Web Services
23.Windows
24.Windows Presentation Foundation
25.XML
26.XML LINQ
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source
C# / C Sharp » Data Types » StringScreenshots 
Some string operations
Some string operations

/*
C#: The Complete Reference 
by Herbert Schildt 

Publisher: Osborne/McGraw-Hill (March 8, 2002)
ISBN: 0072134852
*/
// Some string operations.  
  
using System;  
  
public class StrOps {   
  public static void Main() {   
    string str1 =  
      "When it comes to .NET programming, C# is #1.";   
    string str2 = string.Copy(str1);  
    string str3 = "C# strings are powerful.";   
    string strUp, strLow; 
    int result, idx;  
  
    Console.WriteLine("str1: " + str1)
 
    Console.WriteLine("Length of str1: " +   
                       str1.Length);   
   
    // create upper- and lowercase versions of str1  
    strLow = str1.ToLower()
    strUp =  str1.ToUpper()
    Console.WriteLine("Lowercase version of str1:\n    " 
                      strLow)
    Console.WriteLine("Uppercase version of str1:\n    " 
                      strUp)
 
    Console.WriteLine();   
 
    // display str1, one char at a time.  
    Console.WriteLine("Display str1, one char at a time.")
    for(int i=0; i < str1.Length; i++)  
      Console.Write(str1[i]);   
    Console.WriteLine("\n");   
 
    // compare strings 
    if(str1 == str2)   
      Console.WriteLine("str1 == str2");   
    else   
      Console.WriteLine("str1 != str2");   
   
    if(str1 == str3)   
      Console.WriteLine("str1 == str3");   
    else   
      Console.WriteLine("str1 != str3");   
  
    result = str1.CompareTo(str3);  
    if(result == 0)  
      Console.WriteLine("str1 and str3 are equal");  
    else if(result < 0)  
      Console.WriteLine("str1 is less than str3");  
    else  
      Console.WriteLine("str1 is greater than str3");  
  
    Console.WriteLine();   
 
    // assign a new string to str2  
    str2 = "One Two Three One";  
  
    // search string 
    idx = str2.IndexOf("One");  
    Console.WriteLine("Index of first occurrence of One: " + idx);  
    idx = str2.LastIndexOf("One");  
    Console.WriteLine("Index of last occurrence of One: " + idx);  
      
  }   
}

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