Hi-
I have 6 strings and need to output the following...
- which strings are the same as String 2.
- which strings are the same as String 2, ignoring case.
- Ask the user to enter a word and insert that word into string 4 (string 4 is a concatination of string 1 and string 2 so insert the "word" between string 1 and string 2).
these are the strings:
string s1 = "Hello";
string s2 = "World";
string s3 = "Come visit us at http://www.FormulaOne.com";
string s4 = s1 + s2;
string s5 = "world";
string s6 = string.Copy(s3);
and the array is:
string[] mystrings = new string[] { s1, s2, s3, s4, s5, s6 };
how would i make this code ...so that it takes the array and searches for anything that matches string 2 ("World") but case-insensitive.
the outcome would be string1 (World), string 4 (Hello World) and string 5 (world).
for (int i = 0; i < mystrings.Length; i++)
{
if (mystrings[i].Contains(s2, true))
{
Console.WriteLine("s" + (i + 1).ToString() + " is equal to World (No-Case)");
}
}
Last edited by azukah; February 14th, 2011 at 05:41 PM.
for (int i = 0; i < mystrings.Length; i++)
{
if (mystrings[i].Equals(s2, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("s" + (i + 1).ToString() + " is equal to World (No-Case)");
}
}
* The Best Reasons to Target Windows 8
Learn some of the best reasons why you should seriously consider bringing your Android mobile development expertise to bear on the Windows 8 platform.