Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

TheAireon
Copy link

@TheAireon TheAireon commented Oct 31, 2024

Description

This change adds the .Substring() method description to docs.

Issue Solved

Closes #5571

Type of Change

  • Adding a new entry

Checklist

  • All writings are my own.
  • My entry follows the Codecademy Docs style guide.
  • My changes generate no new warnings.
  • I have performed a self-review of my own writing and code.
  • I have checked my entry and corrected any misspellings.
  • I have made corresponding changes to the documentation if needed.
  • I have confirmed my changes are not being pushed from my forked main branch.
  • I have confirmed that I'm pushing from a new branch named after the changes I'm making.
  • I have linked any issues that are relevant to this PR in the Issues Solved section.

@CLAassistant
Copy link

CLAassistant commented Oct 31, 2024

CLA assistant check
All committers have signed the CLA.

@mamtawardhani mamtawardhani self-assigned this Nov 2, 2024
@mamtawardhani mamtawardhani added new entry New entry or entries c# C# entries status: under review Issue or PR is currently being reviewed labels Nov 2, 2024
@mamtawardhani mamtawardhani linked an issue Nov 3, 2024 that may be closed by this pull request
3 tasks
Copy link
Collaborator

@mamtawardhani mamtawardhani left a 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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.'

Copy link
Collaborator

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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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`.

Copy link
Collaborator

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

Comment on lines +20 to +21
Substring(int startIndex);
Substring(int startIndex, int Length)
Copy link
Collaborator

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)

Comment on lines +24 to +25
- `startIndex`: The index from where the substring starts.
- `Length`: The maximum length of the substring - (Optional).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
- `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..

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reframed for better readability

Comment on lines +32 to +34
string str = "Codecademy";

Console.WriteLine(str.Substring(4));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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));
}
}

Copy link
Collaborator

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```cs
```shell

Copy link
Collaborator

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

Comment on lines +48 to +50
string str = "Codecademy";

Console.WriteLine(str.Substring(2, 6));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```cs
```pseudo


## Codebyte Example

In this Codebyte example, `.Substring()` is used to return a name without it's initial letter.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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:

@TheAireon
Copy link
Author

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?

@mamtawardhani
Copy link
Collaborator

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 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Term Entry] C# Strings .Substring()
3 participants