Skip to content
19 changes: 10 additions & 9 deletions snippets/csharp/VS_Snippets_CLR/string.compare3/CS/comp3.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//<snippet1>
// Sample for String.Compare(String, Int32, String, Int32, Int32)
// Sample for String.Compare(String, Int32, String, Int32, Int32)
using System;

class Sample {
public static void Main() {
//<snippet1>
// 0123456
String str1 = "machine";
String str2 = "device";
Expand All @@ -17,12 +17,13 @@ public static void Main() {
Console.Write("Substring '{0}' in '{1}' is ", str1.Substring(2, 2), str1);
Console.Write("{0} ", str);
Console.WriteLine("substring '{0}' in '{1}'.", str2.Substring(0, 2), str2);

/*
This example produces the following results:

str1 = 'machine', str2 = 'device'
Substring 'ch' in 'machine' is less than substring 'de' in 'device'.
*/
//</snippet1>
}
}
/*
This example produces the following results:

str1 = 'machine', str2 = 'device'
Substring 'ch' in 'machine' is less than substring 'de' in 'device'.
*/
//</snippet1>
27 changes: 14 additions & 13 deletions snippets/csharp/VS_Snippets_CLR/string.compare4/CS/comp4.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
//<snippet1>
// Sample for String.Compare(String, Int32, String, Int32, Int32, Boolean)
// Sample for String.Compare(String, Int32, String, Int32, Int32, Boolean)
using System;

class Sample {
public static void Main() {
//<snippet1>
// 0123456
String str1 = "MACHINE";
String str2 = "machine";
Expand All @@ -26,16 +26,17 @@ public static void Main() {
Console.Write("Substring '{0}' in '{1}' is ", str1.Substring(2, 2), str1);
Console.Write("{0} ", str);
Console.WriteLine("substring '{0}' in '{1}'.", str2.Substring(2, 2), str2);
}
}
/*
This example produces the following results:

str1 = 'MACHINE', str2 = 'machine'
Ignore case:
Substring 'CH' in 'MACHINE' is equal to substring 'ch' in 'machine'.
/*
This example produces the following results:

str1 = 'MACHINE', str2 = 'machine'
Ignore case:
Substring 'CH' in 'MACHINE' is equal to substring 'ch' in 'machine'.

Honor case:
Substring 'CH' in 'MACHINE' is greater than substring 'ch' in 'machine'.
*/
//</snippet1>
Honor case:
Substring 'CH' in 'MACHINE' is greater than substring 'ch' in 'machine'.
*/
//</snippet1>
}
}
33 changes: 17 additions & 16 deletions snippets/csharp/VS_Snippets_CLR/string.indexof1/CS/ixof1.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
//<snippet1>
// Sample for String.IndexOf(Char, Int32)
// Sample for String.IndexOf(Char, Int32)
using System;

class Sample {
public static void Main() {

string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
string str = "Now is the time for all good men to come to the aid of their party.";
//<snippet1>
string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+---";
string br2 = "012345678901234567890123456789012345678901234567890123456789012345678";
string str = "Now is the time for all good men to come to the aid of their country.";
int start;
int at;

Expand All @@ -26,17 +26,18 @@ public static void Main() {
start = at+1;
}
Console.WriteLine();
}
}
/*
This example produces the following results:

/*
This example produces the following results:

All occurrences of 't' from position 0 to 66.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.
All occurrences of 't' from position 0 to 66.
0----+----1----+----2----+----3----+----4----+----5----+----6----+---
012345678901234567890123456789012345678901234567890123456789012345678
Now is the time for all good men to come to the aid of their country.

The letter 't' occurs at position(s): 7 11 33 41 44 55 64
The letter 't' occurs at position(s): 7 11 33 41 44 55 65

*/
//</snippet1>
*/
//</snippet1>
}
}
34 changes: 17 additions & 17 deletions snippets/csharp/VS_Snippets_CLR/string.indexof8/CS/ixof8.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
//<snippet1>
// Sample for String.IndexOf(String, Int32, Int32)
// Sample for String.IndexOf(String, Int32, Int32)
using System;

class Sample {
public static void Main() {

string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+-";
string br2 = "0123456789012345678901234567890123456789012345678901234567890123456";
string str = "Now is the time for all good men to come to the aid of their party.";
//<snippet1>
string br1 = "0----+----1----+----2----+----3----+----4----+----5----+----6----+---";
string br2 = "012345678901234567890123456789012345678901234567890123456789012345678";
string str = "Now is the time for all good men to come to the aid of their country.";
int start;
int at;
int end;
Expand All @@ -32,17 +31,18 @@ public static void Main() {
start = at+1;
}
Console.WriteLine();
}
}
/*
This example produces the following results:

All occurrences of 'he' from position 33 to 66.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.
/*
This example produces the following results:

The string 'he' occurs at position(s): 45 56
All occurrences of 'he' from position 33 to 66.
0----+----1----+----2----+----3----+----4----+----5----+----6----+---
012345678901234567890123456789012345678901234567890123456789012345678
Now is the time for all good men to come to the aid of their country.

*/
//</snippet1>
The string 'he' occurs at position(s): 45 56

*/
//</snippet1>
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// <Snippet1>
using System;
using System;

public class Sample
{
public static void Main() {
// <Snippet1>
String myString = "abc";
bool test1 = myString.Substring(2, 1).Equals("c"); // This is true.
Console.WriteLine(test1);
Expand All @@ -16,11 +16,12 @@ public static void Main() {
catch (ArgumentOutOfRangeException e) {
Console.WriteLine(e.Message);
}

// The example displays the following output:
// True
// True
// Index and length must refer to a location within the string.
// Parameter name: length
// </Snippet1>
}
}
// The example displays the following output:
// True
// True
// Index and length must refer to a location within the string.
// Parameter name: length
// </Snippet1>
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System;
// <Snippet1>
using System;
using System.Globalization;

public class Example
{
public static void Main()
{
// <Snippet1>
string string1 = "brother";
string string2 = "Brother";
string relation;
Expand Down Expand Up @@ -53,6 +53,6 @@ public static void Main()
// 'brother' comes before 'Brother'.
// 'brother' is the same as 'Brother'.
// 'brother' comes after 'Brother'.
// </Snippet1>
}
}
// </Snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ public class Example
{
public static void Main()
{
// <Snippet1>
bool TestForNullOrEmpty(string s)
{
bool result;
result = s == null || s == string.Empty;
return result;
}

string s1 = null;
string s2 = "";
Console.WriteLine(TestForNullOrEmpty(s1));
Console.WriteLine(TestForNullOrEmpty(s2));
}

private static bool TestForNullOrEmpty(string s)
{
bool result;
// <Snippet1>
result = s == null || s == string.Empty;
// </Snippet1>
return result;
}
}