Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
private static void TestMethod1()
{
var str = new [] { 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p' };
// Remove
var t = new char[20];
for (var i = 0; i < 20; i++)
{
t[i] = str[i];
}
// Substring
var r = new char[10];
for (var i = 0; i < str.Length; i++)
{
if (i > 19)
{
break;
}
if (i > 9)
{
r[i - 10] = str[i];
}
}
// IndexOf
var e = 0;
for (var i = 0; i < str.Length; i++)
{
if (str[i] == 'p')
{
e = i;
break;
}
}
// LastIndexOf
var w = 0;
for (var i = str.Length - 1; i > 0; i--)
{
if (str[i] == 'p')
{
w = i;
break;
}
}
// Contains
var q = str.Contains('p'); // Using Linq.
}
private static void TestMethod2()
{
var str = "abcdefghijklmnopabcdefghijklmnopabcdefghijklmnopabcdefghijklmnop";
var t = str.Remove(20);
var r = str.Substring(10, 10);
var e = str.IndexOf("p"); // 15
var w = str.LastIndexOf("p"); // 63
var q = str.Contains("p");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.