Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • The fact that "abcd".Substring(0, 0) returns an empty string does not mean that "abcd" actually starts with an empty string. The result may as well have been declared 'undefined', as null would've been an equally appropriate return value. Commented Nov 22, 2019 at 9:11
  • @TomLint No. You usually combine conditions IE x.FirstName.StartsWith(userEnteredFirstName) && x.LastName.StartsWith(userEnteredLastName) .... This makes the condition work even if one of the entered valeus is empty string. Commented Sep 25, 2020 at 19:14
  • @TomLint But it would be strange to declare the result null or undefined or anything other than '', because why would asking for 1 character from the start give you a string with at most 1 characters but asking for 0 characters from the start would then not give you a string with at most 0 characters but something that isn't a string at all? Commented Dec 6, 2023 at 16:13
  • That's precisely the problem. An empty string isn't really a string at all. "abcd".StartsWith("") should return false, and "abcd".Substring(0,0) really should throw an ArgumentOutOfRangeException for its second argument or, even better, an InvalidOperationException, since retrieving a zero-length sub string is most certainly a programming error. Commented Dec 14, 2023 at 10:52