You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Save the Program.cs file before building or running the code.
38
34
39
35
1. In the EXPLORER panel, to open a Terminal at your TestProject folder location, right-click **TestProject**, and then select **Open in Integrated Terminal**.
A Terminal panel should open, and should include a command prompt showing that the Terminal is open to your TestProject folder location.
42
37
43
38
1. At the Terminal command prompt, to run your code, type **dotnet run** and then press Enter.
44
-
45
-
> [!NOTE]
46
-
>Ifyouseeamessagesaying"Couldn't find a project to run", ensurethattheTerminalcommandpromptdisplaystheexpectedTestProjectfolderlocation. Forexample: `C:\Users\someuser\Desktop\csharpprojects\TestProject>`
> [!NOTE] > If you see a message saying "Couldn't find a project to run", ensure that the Terminal command prompt displays the expected TestProject folder location. For example: `C:\Users\someuser\Desktop\csharpprojects\TestProject>`
40
+
When you run the code, you observe four characters prefixed to the left of the string bring the length to 12 characters long.
41
+
```Output Pad this ```
53
42
54
43
1. To add space or characters to the right side of your string, use the `PadRight()` method instead. 1. Update your code in the Visual Studio Code Editor as follows:
1. Save your code file, and then use Visual Studio Code to run your code. You won't observe any characters added to the end of the string, but they're there.
61
47
@@ -68,22 +54,14 @@ You can also call a second *overloaded* version of the method and pass in whatev
68
54
1. Delete or use the line comment operator `//` to comment out all of the code from the previous step.
69
55
70
56
1. Update your code in the Visual Studio Code Editor as follows:
1. Save your code file, and then use Visual Studio Code to run your code. You should see four dashes prefixing the left of the string that is 12 characters long.
78
-
79
-
```Output
80
-
----Padthis
81
-
Padthis----
82
-
```
60
+
```Output ----Pad this Pad this---- ```
83
61
84
62
Now, apply this newfound knowledge to another real world scenario.
85
63
86
-
## Exercise - Working with padded strings
64
+
## Working with padded strings
87
65
88
66
Suppose you work for a payment processing company that still supports legacy mainframe systems. Often, those systems require data to be input in specific columns. For example, store the Payment ID in columns 1 through 6, the payee's name in columns 7 through 30, and the Payment Amount in columns 31 through 40. Also, importantly, the Payment Amount is right-aligned.
89
67
@@ -96,22 +74,13 @@ To get started, print the Payment ID in the first six columns. You pick some ran
96
74
1. Delete or use the line comment operator `//` to comment out all of the code from the previous step.
97
75
98
76
1. Update your code in the Visual Studio Code Editor as follows:
The `+=` operatorperformsastringconcatenation, takingthepreviousvalueofthevariable `formattedLine` andaddingthenewvaluetoit. It's a shortened equivalent the following code example:
The `+=` operatorperformsastringconcatenation, takingthepreviousvalueofthevariable `formattedLine` andaddingthenewvaluetoit. It's a shortened equivalent the following code example:
0 commit comments