Skip to content

String Remove Start Index Can Be Equal to Length #11300

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

Closed
dtewers opened this issue May 14, 2025 · 1 comment
Closed

String Remove Start Index Can Be Equal to Length #11300

dtewers opened this issue May 14, 2025 · 1 comment

Comments

@dtewers
Copy link

dtewers commented May 14, 2025

Type of issue

Other (describe below)

Description

In the String.Remove method which takes only a startIndex parameter, you may pass a startIndex equal to the length of the string and the string returned is the same as the string passed in. This contradicts the remarks in the documentation:

The value of the startIndex parameter can range from zero to one less than the length of the string instance."

The documentation states that an ArgumentOutOfRangeException is thrown if "startIndex specifies a position that is not within this string." However, this does not happen.

Page URL

https://learn.microsoft.com/en-us/dotnet/api/system.string.remove?view=net-9.0#system-string-remove(system-int32)

Content source URL

https://github.com/dotnet/dotnet-api-docs/blob/main/xml/System/String.xml

Document Version Independent Id

bf50904f-f0ff-1d7f-b23e-6ad2e08930ce

Platform Id

c27a4a36-d9f6-1645-1e78-92b328516d7b

Article author

@dotnet-bot

@dotnet-policy-service dotnet-policy-service bot added the untriaged New issue has not been triaged by the area owner label May 14, 2025
@dtewers
Copy link
Author

dtewers commented May 14, 2025

This method calls Substring which states an ArgumentOutOfRangeException is thrown if "startIndex is less than zero or greater than the length of this instance." That wording would make more sense than the current documentation for the exception in Remove.

@dtewers dtewers closed this as completed May 14, 2025
@dotnet-policy-service dotnet-policy-service bot removed the untriaged New issue has not been triaged by the area owner label May 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant