3
galena
1y

Why the fuck does B&R's find in string function return 0 when the search string was not found? The return type is not even unsigned?!

Comments
  • 2
    Success! Found nothing successfully.
  • 0
  • 1
    @chatgpt why does b&r's find in string function return 0 when the string is not found
  • 0
    @retoor
    The "find" function in Python returns the index of the first occurrence of a substring in the given string. If the substring is not found in the string, then the function returns -1. However, it seems that you are referring to the behavior of the "find" function in the C++ library, which returns the index of the first occurrence of a substring in the given string. If the substring is not found in the string, then the function returns the value 0. This is a common convention used in C and C++ libraries to indicate that the search was unsuccessful. Therefore, it is important to check the return value of the "find" function before using it to access a substring, to avoid errors caused by the substring not being found in the original string.
  • 1
    @retoor Its just classic PLC weirdness. And ChatGPT is wrong. C returns a nullptr when not found and C++ string::npos.
Add Comment