This program is the 2nd program in the following website. When I try to run, it is producing error message. What is the reason for that?
http://msdn.microsoft.com/en-us/library/bc3z4t9d.aspx
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.";
int start;
int at;
start = str.Length - 1;
Console.WriteLine("All occurrences of 'he' from position {0} to 0.", start);
Console.WriteLine("{1}{0}{2}{0}{3}{0}", Environment.NewLine, br1, br2, str);
Console.Write("The string 'he' occurs at position(s): ");
at = 0;
while ((start > -1) && (at > -1))
{
at = str.LastIndexOf("he", start);
if (at > -1)
{
Console.Write("{0} ", at);
start = at - 1;
}
}
Console.Write("{0}{0}{0}", Environment.NewLine);
}
}
/*
This example produces the following results:
All occurrences of 'he' from position 66 to 0.
0----+----1----+----2----+----3----+----4----+----5----+----6----+-
0123456789012345678901234567890123456789012345678901234567890123456
Now is the time for all good men to come to the aid of their party.
The string 'he' occurs at position(s): 56 45 8
*/
Loading
Posted Oct 5, 2013, 9:35 AM
VulpesPosted Oct 5, 2013, 9:20 AM
It's argument 0 (corresponding to the {0} placeholder) in Console.WriteLine and is inserted 3 times into the string to be printed.
There is no need for the placeholders to appear in order or once each. They can appear in any order and one or more times.
Posted Oct 5, 2013, 8:34 AM
Posted Oct 5, 2013, 4:04 AM
Posted Oct 4, 2013, 7:56 PM
VulpesPosted Oct 4, 2013, 11:58 AM
What error are you getting?