The workshop is designed to help you anticipate possible questions, review what you've learned, and begin learning how to put your knowledge into practice.
| 1: | What conversion specifier would you use with printf() to format an integer as a double? Indicate the full syntax required to convert the integer 33. |
| A1: | You use the conversion specifier f to format an integer as a double: printf("%f", 33); |
| 2: | How would you pad the conversion you effected in question 1 with zeros so that the part before the decimal point is four characters long? |
| A2: | You can pad the output from printf() with the padding specifier that is, a space or a zero followed by a number representing the number of characters you want to pad by. printf("%04f", 33); |
| 3: | How would you specify a precision of two decimal places for the floating-point number you have been formatting in the previous questions? |
| A3: | The precision specifier consists of a dot (.) followed by a number representing the precision you want to apply. It should be placed before the conversion specifier: printf("%04.2f", 33); |
| 4: | What function would you use to extract a substring from a string? |
| A4: | The substr() function extracts and returns a substring. |
| 5: | How might you remove whitespace from the beginning of a string? |
| A5: | The ltrim() function removes whitespace from the start of a string. |
| 6: | How would you break up a delimited string into an array of substrings? |
| A6: | The explode() function splits up a string into an array. |
| 7: | Write an SQL query to find the starting position of a substring "grape" in a string "applepearbananagrape". |
| A7: | SELECT LOCATE('grape', 'applepearbananagrape'); |
| 8: | Write a query that selects the last 5 characters from the string "applepearbananagrape". |
| A8: | SELECT RIGHT("applepearbananagrape", 5); |