Skip to content
Merged
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
a5c4810
Merge pull request #1 from dotnet/master
WilliamAntonRohm Jul 12, 2019
686981a
Merge pull request #2 from dotnet/master
WilliamAntonRohm Jul 26, 2019
3811e1c
Merge pull request #3 from dotnet/master
WilliamAntonRohm Jul 30, 2019
03c06fe
Merge pull request #4 from dotnet/master
WilliamAntonRohm Aug 5, 2019
19227f0
updating for Try .NET
WilliamAntonRohm Aug 8, 2019
713445d
fix indentation and moved comments
mairaw Aug 9, 2019
262ca1e
fix indentation
mairaw Aug 9, 2019
11b8b5c
fix indentation
mairaw Aug 9, 2019
e85a12e
use Allman style
mairaw Aug 9, 2019
42ce72a
fix indentation
mairaw Aug 9, 2019
409a65e
fix indentation
mairaw Aug 9, 2019
192bcec
fix indentation
mairaw Aug 9, 2019
b718abf
fix indentation
mairaw Aug 9, 2019
c2203f3
fix indentation
mairaw Aug 9, 2019
b1b1c9a
fix indentation
mairaw Aug 9, 2019
4dd81a2
fix indentation
mairaw Aug 9, 2019
39678f0
fix indentation
mairaw Aug 9, 2019
4a85e8b
fix indentation
mairaw Aug 9, 2019
95e7f20
fix indentation
mairaw Aug 9, 2019
f66aef2
fix indentation
mairaw Aug 9, 2019
f614b71
fix indentation
mairaw Aug 9, 2019
2bd17c6
undo change + indentation
mairaw Aug 9, 2019
c8140e7
remove extra line
mairaw Aug 9, 2019
ed6ecfb
undo change + indentation
mairaw Aug 9, 2019
357a741
undo change + indentation
mairaw Aug 9, 2019
cba909e
fix indentation + output
mairaw Aug 9, 2019
5a2b36b
fix indentation
mairaw Aug 9, 2019
a919ae5
fix indentation
mairaw Aug 9, 2019
b9cc767
fix indentation
mairaw Aug 9, 2019
f904f06
fix indentation
mairaw Aug 9, 2019
250cc75
fix indentation
mairaw Aug 9, 2019
148affb
fix indentation
mairaw Aug 9, 2019
570b9bc
undo change
mairaw Aug 9, 2019
ad11363
undo change
mairaw Aug 9, 2019
b3216d1
fix output
mairaw Aug 9, 2019
4affeec
undo change + fix output
mairaw Aug 9, 2019
d730788
undo change
mairaw Aug 9, 2019
578f129
undo change
mairaw Aug 9, 2019
31f5c6c
undo change
mairaw Aug 9, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions snippets/csharp/VS_Snippets_CLR/string.contains/CS/cont.cs
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
//<snippet1>
using System;
using System;

class Example
{
public static void Main()
{
string s1 = "The quick brown fox jumps over the lazy dog";
string s2 = "fox";
bool b = s1.Contains(s2);
Console.WriteLine("'{0}' is in the string '{1}': {2}",
s2, s1, b);
if (b) {
int index = s1.IndexOf(s2);
if (index >= 0)
Console.WriteLine("'{0} begins at character position {1}",
s2, index + 1);
}
//<snippet1>
string s1 = "The quick brown fox jumps over the lazy dog";
string s2 = "fox";
bool b = s1.Contains(s2);
Console.WriteLine("'{0}' is in the string '{1}': {2}",
s2, s1, b);
if (b) {
int index = s1.IndexOf(s2);
if (index >= 0)
Console.WriteLine("'{0} begins at character position {1}",
s2, index + 1);
}
// This example display the following output:
// 'fox' is in the string 'The quick brown fox jumps over the lazy dog': True
// 'fox begins at character position 17
//</snippet1>
}
}
// This example display the following output:
// 'fox' is in the string 'The quick brown fox jumps over the lazy dog': True
// 'fox begins at character position 17
//</snippet1>
27 changes: 14 additions & 13 deletions snippets/csharp/VS_Snippets_CLR/string.length/CS/length.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
//<snippet1>
using System;
using System;

class Sample
{
public static void Main()
{
string str = "abcdefg";
Console.WriteLine("1) The length of '{0}' is {1}", str, str.Length);
Console.WriteLine("2) The length of '{0}' is {1}", "xyz", "xyz".Length);

int length = str.Length;
Console.WriteLine("3) The length of '{0}' is {1}", str, length);
//<snippet1>
string str = "abcdefg";
Console.WriteLine("1) The length of '{0}' is {1}", str, str.Length);
Console.WriteLine("2) The length of '{0}' is {1}", "xyz", "xyz".Length);

int length = str.Length;
Console.WriteLine("3) The length of '{0}' is {1}", str, length);

// This example displays the following output:
// 1) The length of 'abcdefg' is 7
// 2) The length of 'xyz' is 3
// 3) The length of 'abcdefg' is 7
//</snippet1>
}
}
// This example displays the following output:
// 1) The length of 'abcdefg' is 7
// 2) The length of 'xyz' is 3
// 3) The length of 'abcdefg' is 7
//</snippet1>
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,43 @@ public static class StringExtensions
public static bool Contains(this String str, String substring,
StringComparison comp)
{
if (substring == null)
throw new ArgumentNullException("substring",
if (substring == null)
throw new ArgumentNullException("substring",
"substring cannot be null.");
else if (! Enum.IsDefined(typeof(StringComparison), comp))
throw new ArgumentException("comp is not a member of StringComparison",
else if (! Enum.IsDefined(typeof(StringComparison), comp))
throw new ArgumentException("comp is not a member of StringComparison",
"comp");

return str.IndexOf(substring, comp) >= 0;
return str.IndexOf(substring, comp) >= 0;
}
}
// </Snippet1>

namespace App
{
// <Snippet2>
using System;

public class Example
{
public static void Main()
{
String s = "This is a string.";
String sub1 = "this";
Console.WriteLine("Does '{0}' contain '{1}'?", s, sub1);
StringComparison comp = StringComparison.Ordinal;
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp));

comp = StringComparison.OrdinalIgnoreCase;
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp));
}
public static void Main()
{
// <Snippet2>
String s = "This is a string.";
String sub1 = "this";
Console.WriteLine("Does '{0}' contain '{1}'?", s, sub1);
StringComparison comp = StringComparison.Ordinal;
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp));

comp = StringComparison.OrdinalIgnoreCase;
Console.WriteLine(" {0:G}: {1}", comp, s.Contains(sub1, comp));

// The example displays the following output:
// Does 'This is a string.' contain 'this'?
// Ordinal: False
// OrdinalIgnoreCase: True
// </Snippet2>
}
}
// The example displays the following output:
// Does 'This is a string.' contain 'this'?
// Ordinal: False
// OrdinalIgnoreCase: True
// </Snippet2>
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,26 @@
// <Snippet1>
using System;
using System;

public class Example
{
public static void Main()
{
String[] pairs = { "Color1=red", "Color2=green", "Color3=blue",
public static void Main()
{
// <Snippet1>
String[] pairs = { "Color1=red", "Color2=green", "Color3=blue",
"Title=Code Repository" };
foreach (var pair in pairs) {
int position = pair.IndexOf("=");
if (position < 0)
continue;
Console.WriteLine("Key: {0}, Value: '{1}'",
foreach (var pair in pairs) {
int position = pair.IndexOf("=");
if (position < 0)
continue;
Console.WriteLine("Key: {0}, Value: '{1}'",
pair.Substring(0, position),
pair.Substring(position + 1));
}
}
}

// The example displays the following output:
// Key: Color1, Value: 'red'
// Key: Color2, Value: 'green'
// Key: Color3, Value: 'blue'
// Key: Title, Value: 'Code Repository'
// </Snippet1>
}
}
// The example displays the following output:
// Key: Color1, Value: 'red'
// Key: Color2, Value: 'green'
// Key: Color3, Value: 'blue'
// Key: Title, Value: 'Code Repository'
// </Snippet1>
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//<snippet10>
using System;
using System;

public class SubStringTest {
public static void Main() {
public class SubStringTest
{
public static void Main()
{
//<snippet10>
string [] info = { "Name: Felica Walker", "Title: Mz.",
"Age: 47", "Location: Paris", "Gender: F"};
int found = 0;
Expand All @@ -12,24 +14,26 @@ public static void Main() {
Console.WriteLine(s);

Console.WriteLine("\nWe want to retrieve only the key information. That is:");
foreach (string s in info) {
foreach (string s in info)
{
found = s.IndexOf(": ");
Console.WriteLine(" {0}", s.Substring(found + 2));
}

// The example displays the following output:
// The initial values in the array are:
// Name: Felica Walker
// Title: Mz.
// Age: 47
// Location: Paris
// Gender: F
//
// We want to retrieve only the key information. That is:
// Felica Walker
// Mz.
// 47
// Paris
// F
//</snippet10>
}
}
// The example displays the following output:
// The initial values in the array are:
// Name: Felica Walker
// Title: Mz.
// Age: 47
// Location: Paris
// Gender: F
//
// We want to retrieve only the key information. That is:
// Felica Walker
// Mz.
// 47
// Paris
// F
//</snippet10>
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// <Snippet2>
using System;
using System;

public class Example
{
public static void Main()
{
String s = "aaaaabbbcccccccdd";
Char charRange = 'b';
int startIndex = s.IndexOf(charRange);
int endIndex = s.LastIndexOf(charRange);
int length = endIndex - startIndex + 1;
Console.WriteLine("{0}.Substring({1}, {2}) = {3}",
public static void Main()
{
// <Snippet2>
String s = "aaaaabbbcccccccdd";
Char charRange = 'b';
int startIndex = s.IndexOf(charRange);
int endIndex = s.LastIndexOf(charRange);
int length = endIndex - startIndex + 1;
Console.WriteLine("{0}.Substring({1}, {2}) = {3}",
s, startIndex, length,
s.Substring(startIndex, length));
}

// The example displays the following output:
// aaaaabbbcccccccdd.Substring(5, 3) = bbb
// </Snippet2>
}
}
// The example displays the following output:
// aaaaabbbcccccccdd.Substring(5, 3) = bbb
// </Snippet2>
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
// <Snippet3>
using System;
using System;

public class Example
{
public static void Main()
{
String s = "<term>extant<definition>still in existence</definition></term>";
String searchString = "<definition>";
int startIndex = s.IndexOf(searchString);
searchString = "</" + searchString.Substring(1);
int endIndex = s.IndexOf(searchString);
String substring = s.Substring(startIndex, endIndex + searchString.Length - startIndex);
Console.WriteLine("Original string: {0}", s);
Console.WriteLine("Substring; {0}", substring);
}
public static void Main()
{
// <Snippet3>
String s = "<term>extant<definition>still in existence</definition></term>";
String searchString = "<definition>";
int startIndex = s.IndexOf(searchString);
searchString = "</" + searchString.Substring(1);
int endIndex = s.IndexOf(searchString);
String substring = s.Substring(startIndex, endIndex + searchString.Length - startIndex);
Console.WriteLine("Original string: {0}", s);
Console.WriteLine("Substring; {0}", substring);

// The example displays the following output:
// Original string: <term>extant<definition>still in existence</definition></term>
// Substring; <definition>still in existence</definition>
// </Snippet3>
}
}
// The example displays the following output:
// Original string: <term>extant<definition>still in existence</definition></term>
// Substring; <definition>still in existence</definition>
// </Snippet3>
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
// <Snippet4>
using System;
using System;

public class Example
{
public static void Main()
{
String value = "This is a string.";
int startIndex = 5;
int length = 2;
String substring = value.Substring(startIndex, length);
Console.WriteLine(substring);
}
}
// The example displays the following output:
// is
// </Snippet4>
public static void Main()
{
// <Snippet4>
String value = "This is a string.";
int startIndex = 5;
int length = 2;
String substring = value.Substring(startIndex, length);
Console.WriteLine(substring);

// The example displays the following output:
// is
// </Snippet4>
}
}
Loading