Skip to content

String Remove Start Index Can Be Equal to Length #11301

@dtewers

Description

@dtewers

Type of issue

Exception documentation is not accurate.

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.

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 sense to reuse for the exception documentation in this method.

Note: accidentally closed the original issue here: #11300.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions