Monday, 26 November 2012

c# for dummies: c sharp programming

c# for dummies: c sharp programming: String Concatenation string variables can be connected together to build larger strings via the C# + operator. As you may know, this tec...

c sharp programming

String Concatenation




string variables can be connected together to build larger strings via the C# + operator. As you may
know, this technique is formally termed string concatenation. Consider the following new helper
function:

static void StringConcatenation()
{
  Console.WriteLine("=> String concatenation:");
  string s1 = "Programming the ";
  string s2 = "PsychoDrill (PTP)";
  string s3 = s1 + s2;
  Console.WriteLine(s3);
  Console.WriteLine();
}

c# for dummies: string manipulation

c# for dummies: string manipulation:                           Basic String Manipulation Working with the members of System.String is as you would expect. Simply declare a strin...

string manipulation

                          Basic String Manipulation

Working with the members of System.String is as you would expect. Simply declare a string variable
and make use of the provided functionality via the dot operator. Be aware that a few of the members of
System.String are static members and are, therefore, called at the class (rather than the object) level.
Assume you have created a new Console Application project named FunWithStrings. Author the
following method, which should be called from within Main():

static void BasicStringFunctionality()
{
  Console.WriteLine("=> Basic String functionality:");
  string firstName = "Freddy";
  Console.WriteLine("Value of firstName: {0}", firstName);
  Console.WriteLine("firstName has {0} characters.", firstName.Length);
  Console.WriteLine("firstName in uppercase: {0}", firstName.ToUpper());
  Console.WriteLine("firstName in lowercase: {0}", firstName.ToLower());
  Console.WriteLine("firstName contains the letter y?: {0}",
    firstName.Contains("y"));
  Console.WriteLine("firstName after replace: {0}", firstName.Replace("dy", ""));
  Console.WriteLine();
}

Not too much to say here, as this method simply invokes various members, such as ToUpper() and
Contains(), on a local string variable to yield various formats and transformations.




Tuesday, 13 November 2012

c# for dummies: c sharp programming

c# for dummies: c sharp programming: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StringManipulationPost {     class Program  ...

c sharp programming

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StringManipulationPost
{
    class Program
    {
        static void Main(string[] args)
        {
          
                string[] strings = { "started", "starting", "ended", "ending" };
 // test every string to see if it starts with "st"
 for ( int i = 0; i < strings.Length; i++ )
    if (strings[ i ].StartsWith( "st" )   )
       Console.WriteLine( "\"" + strings[ i ] + "\"" +
          " starts with \"st\"" );
 Console.WriteLine();
 // test every string to see if it ends with "ed"
 for ( int i = 0; i < strings.Length; i++ )
    if (  strings[ i ].EndsWith( "ed" ) )
       Console.WriteLine( "\"" + strings[ i ] + "\"" +
          " ends with \"ed\"" );
 Console.WriteLine();
//strings[ i ].StartsWith( "st" )
//strings[ i ].EndsWith( "ed" )


              Console.ReadLine();
 
        }
    }
}

c# for dummies: c sharp classes

c# for dummies: c sharp classes: using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace StringManipulationPost {     class Program  ...