Skip to content

Padding Strings should specify what it does with strings shorter than the Int32 #4392

Closed

Description

@ocdtrekkie

So, I had an issue where I was getting an exception with a Substring function, presumably because I surmised sometimes the string is shorter than I expected. This led me to want to pad my strings, but wanted to make sure I wouldn't find any unexpected behavior and I found myself on PadRight's documentation, here: https://msdn.microsoft.com/en-us/library/system.string.padright(v=vs.110).aspx?f=255&MSPPError=-2147217396

Then I moved to the new one, here: https://docs.microsoft.com/en-us/dotnet/standard/base-types/padding#comments-container

Neither one answered my question: What would it do if the string was longer than the Int32 passed to pad it to? Would it truncate my string? Would it simply return the string as it was? Would it throw an error? The answer, mind you, from actually testing it in Visual Studio, is option B: It just leaves the string alone, which is a good reasonable way for .NET to behave.

...But I was annoyed this wasn't in the documentation.

First time visitor, figured I'd ask if it's okay to add that.

Activity

  1. self-assigned this
    on Feb 15, 2018
  2. rpetrusha commented on Feb 15, 2018

    @rpetrusha
    Contributor

    Thanks for opening this issue and identifying an information gap in the documentation, @ocdtrekkie. Feel free to open an issue when you notice missing, incomplete, or inaccurate information. If you're interested in addressing the issue yourself, you can also open a pull request.

    We'll add information on padding a string whose length already exceeds the padded length in the near future.

  3. rpetrusha commented on Mar 14, 2018

    @rpetrusha
    Contributor

    The MSDN link is to the overload list page, which is intended to contain minimal information. Since the overload list page does not exist on docs.microsoft.com, the documentation for both overloads of String.PadLeft and String.PadRight document what happens if the desired length is less than the actual string length. As a result, only the Padding Strings in .NET topic needs modification.

  4. ocdtrekkie commented on Mar 14, 2018

    @ocdtrekkie
    Author

    Ah! I do see the answer if I click on one of the overloads in the MSDN link, and on the respective String.PadLeft/Right pages on Docs. I guess I didn't dig deep enough! Your modification to the Padding Strings in .NET page should definitely help though, thank you.

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions