Namespace StringManipulation
Class Tester
Public Sub Run()
Dim s1 As String = "abcd"
Dim s2 As String = "ABCD"
'concatentation method
Dim s3 As String = String.Concat(s1, s2)
Console.WriteLine("s3 concatenated from s1 and s2: {0}", s3)
'use the overloaded operator
Dim s4 As String = s1 & s2
Console.WriteLine("s4 concatenated from s1 & s2: {0}", s4)
End Sub 'run
Public Shared Sub Main()
Dim t As New Tester()
t.Run()
End Sub 'main
End Class
End Namespace
Public Sub RunCopy()
Dim s1 As String = "scdb"
Dim s2 As String = "CATNIP"
'the string copy method
Dim s5 As String = String.Copy(s2)
Console.WriteLine("s5 copied from s2: {0}", s5)
'use the overloaded operator
Dim s6 As String = s5
Console.WriteLine("s6 = s5: {0}", s6)
End Sub 'Run
Public Sub RunEquality()
Dim s1 As String = "qwerty"
Dim s2 As String = "QWERTY"
'the string copy method
Dim s5 As String = String.Copy(s2)
Console.WriteLine("s5 copied from s2: {0}", s5)
'copy with the overloaded operator
Dim s6 As String = s5
Console.WriteLine("s6 = s5: {0}", s6)
'member method
Console.WriteLine("Does s6.Equals(s5)?: {0}", s6.Equals(s5))
'shared method
Console.WriteLine("Does Equals(s6, s5)?: {0}", String.Equals(s6, s5))
End Sub 'Rnu Equality
Public Shared Sub Main()
Dim t As New Tester()
t.RunCopy()
Console.WriteLine()
t.RunEquality()
End Sub
Class Tester
Public Sub Run()
Dim s1 As String = "abcd"
Dim s2 As String = "ABCD"
Dim s3 As String = "Liberty Associates, Inc. provides "
s3 = s3 & "custom .NET development"
'the string copy method
Dim s5 As String = String.Copy(s2)
Console.WriteLine("s5 copied from s2: {0}", s5)
'the length
Console.WriteLine("String s3 is {0} characters long. ", s5.Length)
Console.WriteLine()
Console.WriteLine("s3: {0}", s3)
'test whether a String ends with a set of characters
Console.WriteLine("s3: ends with Training?: {0}", s3.EndsWith("training"))
Console.WriteLine("Ends with Development?: {0}", s3.EndsWith("development"))
Console.WriteLine()
'return the index fo teh string
Console.WriteLine("The first occurrrence of provides ")
Console.WriteLine("in s3 is {0}", s3.IndexOf("provides"))
'hold the location of provides as an integer
Dim location As Integer = s3.IndexOf("provides")
'insert the word usually before "provides"
Dim s10 As String = s3.Insert(location, "usually ")
Console.WriteLine("s10: {0}", s10)
'you can combine the two as follows:
Dim s11 As String = s3.Insert(s3.IndexOf("provides"), "usually ")
Console.WriteLine("s11: {0} ", s11)
Console.WriteLine()
'use the mid function to replace within the string
Mid(s11, s11.IndexOf("usually") + 1, 9) = "always!"
Console.WriteLine("s11 now: {0}", s11)
End Sub 'run
Public Shared Sub Main()
Dim t As New Tester()
t.Run()
End Sub 'Main
End Class
namespace practiceTuesday
{
class Program
{
static void Main(string[] args)
{
Person al = new Person("Al", 29);
al.Print();
}
}
class Person
{
//fields areadonly members that define the data the enclosing type consists of
private string _name;
private int _age;
public Person(string name, int age)
{
_name = name;
_age = age;
}
public void Print()
{
Console.WriteLine(_name + " is " + _age + " years young");
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ClassSample
{
class Program
{
static void Main(string[] args)
{
Vertex3d vd = new Vertex3d();
Vertex3d vd2 = new Vertex3d(4.5, 5.5, 8.0);
vd.Print();
vd2.Print();
}
}
public class Vertex3d
{
public const string Name = "Vertex";
private readonly int ver;
private double _x;
private double _y;
private double _z;
public void Print()
{
Console.WriteLine("{0} - {1} - {2}", _x, _y, _z);
}
//properties
public double X
{
get { return _x; }
set { _x = value; }
}
public double Y
{
get { return _y; }
set { _y = value; }
}
public double Z
{
get { return _z; }
set { _z = value; }
}
//method
public void SetToOrigin()
{
X = Y = Z = 0.0;
}
public static Vertex3d Add(Vertex3d a, Vertex3d b)
{
Vertex3d result = new Vertex3d();
result.X = a.X + b.X;
result.Y = a.Y + b.Y;
result.Z = a.Z + b.Z;
return result;
}
public Vertex3d()
{
_x = _y = _z = 0.0;
}
public Vertex3d(double x, double y, double z)
{
this._x = x;
this._y = y;
this._z = z;
}
}
}
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment