You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is very nice that .NET checks array bounds, including character array bounds in string objects and throws an exception when index and or combination with length is out of string bounds.
However, strings are, from the dawn of time, texts of variable lengths, and many languages before and after the advent of .NET era had and having substring functions that are tolerant to out-of-bound errors by returning just what can be returned, including an empty string, if there are no characters in the required ranges.
Is it that hard or religiously dangerous to add two methods with three versions, like this (s being some string object)?
s.Left(maxLength)
s.Left(startIndex, maxLength) and
s.Right(MaxLength)
which would return a substring object on a best-effort basis.
For example:
"Leopard". Left(3) would return "Leo", while "Leopard". Left(13) would just return "Leopard",
"Lioness". Left(4, 2) would return "es". while "Lioness". Left(4, 10) would return "ess" and "Lioness". Left(10, 15) would return "", and
"Aligator". Right(5) would return "gator", while "Aligator". Right(20) would just return "Aligator"
Nothing more, nothing less.
Yes, bounds checking are pretty fine thing to have and use, but sometimes (more often than rarely), this would be the right way to process substrings, so I do not have to write:
s.Substring(0, Math.Max(maxLength, s.Length)) instead of s.Left(maxLength)
I am begging for this for thirty years and, writing suggestions about that from time to time - yet, no results.
Yes, . Clear() method on StringBuilder class was my suggestion, back then, when somebody kindly reealized that it is simple to implement and would not harm anyone.
This suggestion would also be easy to implement, would break nothing and would be great for all types of casual programming cases (think also of C# scripts), when array bounds checking is just an irrational burden...
So, pretty please, give us that tiny bit of great user (programmer) experience....
Regards,
Gjuro Kladaric
Original Comments
Feedback Bot on 28/2/2025, 02:24 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
The text was updated successfully, but these errors were encountered:
This issue has been moved from a ticket on Developer Community.
It is very nice that .NET checks array bounds, including character array bounds in string objects and throws an exception when index and or combination with length is out of string bounds.
However, strings are, from the dawn of time, texts of variable lengths, and many languages before and after the advent of .NET era had and having substring functions that are tolerant to out-of-bound errors by returning just what can be returned, including an empty string, if there are no characters in the required ranges.
Is it that hard or religiously dangerous to add two methods with three versions, like this (s being some string object)?
which would return a substring object on a best-effort basis.
For example:
Nothing more, nothing less.
Yes, bounds checking are pretty fine thing to have and use, but sometimes (more often than rarely), this would be the right way to process substrings, so I do not have to write:
I am begging for this for thirty years and, writing suggestions about that from time to time - yet, no results.
Yes, . Clear() method on StringBuilder class was my suggestion, back then, when somebody kindly reealized that it is simple to implement and would not harm anyone.
This suggestion would also be easy to implement, would break nothing and would be great for all types of casual programming cases (think also of C# scripts), when array bounds checking is just an irrational burden...
So, pretty please, give us that tiny bit of great user (programmer) experience....
Regards,
Gjuro Kladaric
Original Comments
Feedback Bot on 28/2/2025, 02:24 PM:
We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.
The text was updated successfully, but these errors were encountered: