-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding Substring term. #5580
base: main
Are you sure you want to change the base?
Adding Substring term. #5580
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @TheAireon, thank you for contributing to Codecademy Docs, the entry is nicely written! 😄
I've suggested a few changes, could you please review and modify those at your earliest convenience? Thank you! 😃
@@ -0,0 +1,76 @@ | |||
--- | |||
Title: '.Substring()' | |||
Description: 'Returns the substring of a string instance starting at a given index' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description: 'Returns the substring of a string instance starting at a given index' | |
Description: 'Returns the substring of a string instance starting at a given index.' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
full stop missing
- 'paths/computer-science' | ||
--- | ||
|
||
The **`.Substring()`** method is a string method that returns a substring of a string starting at the given index number, it will return all characters unless a maximum length is given. This method returns `Empty` if the index is greater than the length of the string instance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The **`.Substring()`** method is a string method that returns a substring of a string starting at the given index number, it will return all characters unless a maximum length is given. This method returns `Empty` if the index is greater than the length of the string instance. | |
The **`.Substring()`** method is a string method that returns a substring of a string starting at the specified index. It will return all characters from that index to the end unless a maximum length is specified. If the starting index equals the string length, it returns an empty string (`""`). If the index is greater than the string length, it throws an `ArgumentOutOfRangeException`. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
corrected the definition as it does not return Empty
Substring(int startIndex); | ||
Substring(int startIndex, int Length) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can write this as:
.Substring(int startIndex)
Or, alternatively:
.Substring(int startIndex, int length)
- `startIndex`: The index from where the substring starts. | ||
- `Length`: The maximum length of the substring - (Optional). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `startIndex`: The index from where the substring starts. | |
- `Length`: The maximum length of the substring - (Optional). | |
- `startIndex`: The index from where the substring starts. | |
- `Length` (Optional): The number of characters to include in the substring.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reframed for better readability
string str = "Codecademy"; | ||
|
||
Console.WriteLine(str.Substring(4)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string str = "Codecademy"; | |
Console.WriteLine(str.Substring(4)); | |
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
string str = "Codecademy"; | |
Console.WriteLine(str.Substring(4)); | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
included the code in a class
|
||
It returns the following output. | ||
|
||
```cs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```cs | |
```shell |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output is always wrapped in the shell
block
string str = "Codecademy"; | ||
|
||
Console.WriteLine(str.Substring(2, 6)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string str = "Codecademy"; | |
Console.WriteLine(str.Substring(2, 6)); | |
using System; | |
public class Program | |
{ | |
public static void Main() | |
{ | |
string str = "Codecademy"; | |
Console.WriteLine(str.Substring(2, 6)); | |
} | |
} |
|
||
## Example 2 | ||
|
||
Here, `.Substring()` is used with the optional "Length" value so that it returns a string composed of the 6 characters from index 2. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, `.Substring()` is used with the optional "Length" value so that it returns a string composed of the 6 characters from index 2. | |
In this example, `.Substring()` is used with the optional `length` parameter to return a substring of 6 characters starting from index `2` of the string `"Codecademy"`. |
``` | ||
|
||
It returns the following output. | ||
```cs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
```cs | |
```pseudo |
|
||
## Codebyte Example | ||
|
||
In this Codebyte example, `.Substring()` is used to return a name without it's initial letter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this Codebyte example, `.Substring()` is used to return a name without it's initial letter. | |
Run the Codebyte example, to understand how the `.Substring()` method works: |
Hello. Thank you for the helpful comments. I'm sorry for the amount of changes, I am rather new to this. Should I change the file, commit the new changes and do another pull request? or do I change it within Github itself? |
You can change it within this PR itself. You should see a "commit suggestion" button wherever I have suggested changes, just click on it and for the comments, you will have to make changes in your local file and push the changes on the same branch. So no new pr is needed 😃 |
Description
This change adds the .Substring() method description to docs.
Issue Solved
Closes #5571
Type of Change
Checklist
main
branch.Issues Solved
section.