Modify the C # Substring () function,
In the Substring () function of C #, If we accidentally input a length greater than the string, we will receive an exception:StartIndex cannot be larger than length of string.
For example:
After the webpage is running:
Insus. NET requires that, as long as a value greater than or equal to 0 is input, it can help us intercept, if the input value is greater than the length of the string, it returns a string, this is what we need. Therefore, Insus. NET writes an extension method, and this method is overloaded:
Now we can use InsusSubstring () to load the string and list two examples. The first one is to take 3 characters:
In the second example, the input is truncated by 15 characters. Because the 15 characters are 5 characters in length, but there is no exception at runtime, the entire string is taken out.
In the extended class, Insus. NET does not post the second overload method. If you want to improve it, please refer to the first method and give full play to your own capabilities.
Change the C language program
[Error code location]
Else printf ("date error \ n ");
[Correction Method]
1. Double quotation marks (3rd error reminders, that is, it is used .)
Here, else printf ("date error \ n"); the two "quotation marks" in the brackets are not "quotation marks" in the English state. After deletion, switch the Input Method to the English state and re-"quotation marks ".
It is best to repeat the parentheses.
2. if-else pairing error (four error reminders, that is, it .)
Here, else printf ("date error \ n"); is a pair, the code between them should be enclosed in a pair of curly braces.
In this case, the {} content belongs to if (year> = 0), and else also finds the pairing.
Otherwise, the content managed by if (year> = 0) is incorrect, rarely; While else printf ("date error \ n"); there is no matching if statement, four syntax errors are caused.
3. Warning content
Warning: no newline at end of file (warning: no blank lines exist at the end of the file)
Solution: in the last row, press enter to add an empty row. The warning disappears.
C language. You can change the program to enable two integer exchanges,
# Include <stido. h> void swap (int * x, int * y); int main () {int a, B; scanf ("% d", & a, & B ); printf ("before calling the function: \ n"); printf ("a = % d, B = % d \ n", a, B); swap (&, & B); printf ("\ n"); printf ("a = % d, B = % d \ n", a, B); return 0 ;} void swap (int * x, int * y) {int t; t = * x; * x = * y; * y = t; printf ("inside the call function: \ n "); printf (" x = % d, y = % d \ n ", * x, * y );}