Monday, 5 August 2019

optimization - Checking for string contents? string Length Vs Empty String



Which is more efficient for the compiler and the best practice for checking whether a string is blank?





  1. Checking whether the length of the string == 0

  2. Checking whether the string is empty (strVar == "")



Also, does the answer depend on language?


Answer



Yes, it depends on language, since string storage differs between languages.





  • Pascal-type strings: Length = 0.

  • C-style strings: [0] == 0.

  • .NET: .IsNullOrEmpty.



Etc.


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print ...